Ipad and Iphone detection using PHP

By

May 25, 2010PHP8 Comments

Like the basic browser detection you can easily detect  ipad  in your website using PHP script.This is very useful in developing ipad specific web applications.

The PHP script uses the $_SERVER[‘HTTP_USER_AGENT’].

<?php
echo($_SERVER[‘HTTP_USER_AGENT’]);
?>

A simple script to detect ipad and redirect to a page.

apple-ipad

apple-ipad

< ?php
    if(strstr($_SERVER['HTTP_USER_AGENT'],’iPad’))
  {
       header(‘Location: http://www.devlup.com/ipad’);
  }

?>

Similarly iphone can be detected using the same way

apple-iphone

apple-iphone

< ?php
     if(strstr($_SERVER['HTTP_USER_AGENT'],’iPod’))
   {

       header(‘Location: http://www.devlup.com/iphone’);
   }

?>

Developer’s Link:

strstr , get_ browser

Try this script on your ipad and share your views.

8 Responses to “Ipad and Iphone detection using PHP”
  1. kannan

    nice to know, and very helpful.

  2. Victor Rodriguez

    Is it possible to do applications with PHP that works or can be run on iphones or iPad?

    • Jeyaganesh

      hi victor,
      You can build iphone and ipads applications without knowing objective C.
      U can build apps just with html and java script too. there are many frameworks in the market that help u do so.
      Ex,
      appcelerator,
      Phonegap,
      Buildanapp…. etc

  3. cheif

    I am doing a news website using PHP & Mysql can this script run it in Iphone & Ipad

  4. Jeyaganesh

    you can use this script to detect the users using iphone and ipad to visit your page

  5. michael

    Hello Jeyaganesh,

    I have tried your ipad php detection code – with no luck

    I have 2 questions.

    1. What do you call the php file – eg index.php ?

    2. Where do you put the php file on your server – eg /public_html ?

    Thanks

  6. Jeyaganesh

    Hello michael

    index.php is the default page of the website it will be in the www root.

    The script which I mentioned here is to detect whether the user is using an ipad/iphone to view the site..

    you can reply,if you still need clarification about it.

    Thanks

  7. Chantal

    If it’s not working it’s probably because this entry was made using an apple instrument so what should be ‘iPad’ becomes ’iPad’ which translates to something like iPad on Unix.
    My advice: don’t use apples.

    They’re far too expensive anyways.

Leave a Reply

*