Ipad and Iphone detection using PHP

by Jeyaganesh on May 25, 2010

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.

Related posts:

HTML5 news
Free iPhone Programming Ebook
How smart is your Theme?  How good is your support? Check out ThesisTheme for WordPress.

{ 8 comments… read them below or add one }

kannan May 27, 2010 at 2:47 pm

nice to know, and very helpful.

Reply

Victor Rodriguez September 19, 2010 at 3:35 am

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

Reply

Jeyaganesh September 19, 2010 at 9:31 am

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

Reply

cheif January 22, 2011 at 12:18 am

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

Reply

Jeyaganesh January 26, 2011 at 8:05 am

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

Reply

michael February 1, 2011 at 4:49 pm

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

Reply

Jeyaganesh February 1, 2011 at 5:28 pm

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

Reply

Chantal July 20, 2011 at 2:46 pm

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.

Reply

Leave a Comment

Previous post:

Next post: