Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


How can I auto-detect that someone's on an Apple iPad?

I'm working on my Web site and now that the Apple iPad is out, I'd like to customize my greeting for people using that device. How can I auto-detect that they're on an iPad?


Dave's Answer:

There are a ton of tools to help you with this particular task, and I've written about it before too (see How to detect an iPhone web browser). The basic idea is that every Web browser on every hardware platform sends what's called a USER_AGENT identifier. Almost all of the time they're accurate, but some test browsers have the ability to pretend they're something else (known in the biz as "spoofing", actually).

On my Mac OS X system, for example, when I am hitting Web pages within Google's Chrome browser, here's what is sent to the Web server for each and every transaction I do, whether an HTML page, PHP search result or even ask for a photo or other image:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.347.0 Safari/533.2

You can check your Web browser too. Just pop over to Microsystools and find out.

Now, the question of the moment is, what string does it show when you're on an Apple iPad?

Here's the answer:

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version /4.0.4 Mobile/7B367 Safari/531.21.10

Pretty ugly, really, but the key thing to notice is that the first word within parens identifies the hardware platform. If you're writing code of some sort, simply grab the USER_AGENT string, then check that first word.

Oh, if you're on an iPhone and you go to the same page, here's the USER_AGENT you are sending on each query:

Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version /4.0 Mobile/7E18 Safari/528.16

Good luck!

Looking for iPad help? Good news; you've found it!


More Useful Apple iPad Help Articles:
✔   Closed captioning for TV shows and movies on my iPhone?
Hey Dave, I saw your article from a few days about How to Turn on Closed Captioning in iTunes and am wondering if...
✔   Capture and email a portion of an iPad screen display?
I would like to be able to clip out a rectangular section of any screen on the iPad (not just web pages) and...
✔   Review: Verticus for iPad
iOS gamers everywhere are familiar with the genre of infinite forward progress apps - Mega Jump, Canabalt, and a host of other run/jump/fly-until-you-die...
✔   Enable Apple 2-Step Verification in iTunes?
I keep reading all these articles about iTunes account security and people having their accounts hacked. I have 2-step security verification set up...
✔   The Best Free iOS Apps?
Whether the best things in life are free is an issue hotly debated over. With iOS apps, this may or may not be...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  




Categorized: Apple iPad Help , HTML, JavaScript and Web Site Programming   (Article 9374, Written by )
Tagged: apple ipad, apple iphone, browser detection, google chrome, web programming
Previous: How do I create an event for my Facebook group?
Next: How do I copy Keynote presentations onto my Apple iPad?




Reader Comments To Date: 3

Carlos Cardona said, on April 5, 2010 9:49 PM:

Thanks for this post! Very useful.

I created a small tutorial that shows how to detect the ipad browser and redirect to an appropriate directory.

http://cardonadesigns.com/wordpress/2010/04/04/using-php-to-detect-the-ipad-user-agent/

sam said, on June 1, 2010 1:39 AM:

I also need to redirect iphone users to a html version of the site since flash isn’t read by apple iphones!
but I need a HTML code to do that since my index page is in html and all the other php etc etc seem not working (
please Help!

ansia said, on May 22, 2012 7:42 PM:

that s what i was looking for...! thanks

Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!

I do have a comment, now that you mention it!











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.