Ipod and Iphone PHP detection

Ipod and Iphone PHP detection

1 Star2 Stars3 Stars4 Stars5 Stars
Posted on March 13, 2009

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

Recent shares

More tutorials from Papermashup
Comments
2 discussions around Ipod and Iphone PHP detection
  1. Ann says:

    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

  2. Rocky says:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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

Looking for a registry cleaner to speed up your PC and show a full diagnostics?
Faster surfing with Dish Network High Speed Internet

Never miss an update from Papermashup

Get notified about the latest tutorials and downloads.

Subscribe by Email

Get alerts directly into your inbox after each post and stay updated.
Subscribe
OR

Subscribe by RSS

Add our RSS to your feedreader to get regular updates from us.
Subscribe

Get in contact

Please use the form below to get in touch.

About Me

I'm Ashley Ford, Co-founder and Technical Director at Harkable.com London, UK. Previously I worked at InMobi, Spotify and MySpace. My interests include photography and making short videos I'm also an avid F1 fan. I'm always working on side projects. Here are a few: Easy Poll, We Deliver.



What do you specialise in?

I spend a lot of time coding in PHP and MySQL, as well as front end XHTML and CSS. I also specialise in javascript and the jQuery framework as well as being an avid designer. You can find me on dribbble

Interested in advertising?

If you'd like to advertise on Papermashup.com you can find details here Or use the contact link below for further advertising opportunities.

How do I contact you

You can contact me here. and I'm available for consultation, freelance, programming book reviews.

Get on the mailing list

Join over 3000 people who have subscribed to the Papermashup inbox message, and be the first to find out about tutorial, competitions and giveaways.