Detecting iPhone visitors with PHP

Detecting iPhone visitors with PHP

More and more internet traffic is generated by the iPhone and iPod touch.

The PHP snippet below shows you how to automatically redirect your users to a page which is optimized for the iPhone Safari browser.


if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
{
// Change your URL below
header('Location: http://www.domain.com/iphone');
exit();
}
Share and Enjoy:
  • email
  • Twitter
  • LinkedIn
  • Facebook
  • Google Bookmarks
  • RSS
Your Ad Here

1 Comment to “Detecting iPhone visitors with PHP”

  1. Neo says:

    good idea
    i think it would be better if we use strtolower to match the userAgent

    thanks 4 ur great articles, U ROCK!

    $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);

    if(preg_match(‘/iphone/’, $userAgent) || preg_match(‘/ipod/’, $userAgent)) {
    //do whatever u want
    }

Leave a Reply

You must be logged in to post a comment.