Ipod and Iphone PHP detection

13 March 2009| One Comment| Print

This is a useful script to re-direct Iphone and Ipod users to a specific page. You could use this if your getting a lot of mobile traffic and your current site isn’t optimised for it. Or for branching out and developing a mobile site for your visitors!

There’s a bad point to using this right?

Sure thing. As a developer you may find it logical to re-direct your users to a stripped down mobile version of your site, however there are times when they may not want to view this, and just want to see the normal site. Its worth keeping in mind before you implement if across your whole platform!

Remember as the code is sending header information it needs to go right at the top of the page before any HTML code

The code:


if(strstr($_SERVER['HTTP_USER_AGENT'],'iPod') || strstr($_SERVER['HTTP_USER_AGENT'],'iPhone'))
{
	header('Location: http://example.com/iphoneSpecificPage');
	exit();
}

Share:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • DZone
  • Reddit
  • Netvibes

One Comment

  • Rocky

    I never knew that you could use superglobals on a Ipod / iphone i didnt think that they had had ‘HTTP_USER_AGENTS’

Leave a comment...

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled site. To get your own globally-recognized-avatar, register at Gravatar.

Your Ad Here