To detect if the device a user is using is an iOS device, you can use the following code snippet in PHP:
<?php if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPad')) { echo "iPhone or iPad"} else { echo "Other, non-iOS device" } ?>
This will check if in the user agent string the words ‘iPhone’ or ‘iPad’ occur.
You can use this code snippet in your web development projects in order to detect whether your visitor is browser your website with an iOS device or non. Based on this information, you can display custom text or do any other action you may like. For example, you may want to display a banner to suggest an app download for iOS devices and show nothing when a visitor is browser from a desktop or laptop.
One thought on “Detect iOS device (iPhone/iPad) in PHP”