Detect iOS device (iPhone/iPad) in PHP

To detect if the device a user is using is an iOS device, you can use the following code snippet in 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.


Author Bio

Thank you for your interest in my blog! On this miniblog, I write mostly short (technical) blog posts that might interest other people. Read more about me or feel free to contact me.


One thought on “Detect iOS device (iPhone/iPad) in PHP

  1. Pingback: Escapando (parcialmente) do Instagram – Mandrião Press

Leave a Reply

Your email address will not be published. Required fields are marked *