Papermashup

Subscribe


Tweets


"RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…"

@ashleyford 5 days ago

"Is there ever a time that @DFS doesn't have a sale on?"

@ashleyford 1 week ago

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Ipod and Iphone PHP detection

AshleyAshley

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();
}


Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Comments 2
  • Ann
    Posted on

    Ann Ann

    Reply Author

    Ashley, it’s recommended to use strpos rather than strstr (php.net/strstr). Thanks for the share.

    Because you can access the same browser data in javascript you can detect user browser on client-side. It seems it’s already been well documented :))

    http://jquery-howto.blogspot.com/2010/09/iphone-ipod-detection-using-jquery.html


  • Rocky
    Posted on

    Rocky Rocky

    Reply Author

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