How do I detect if the user is on a pc or mobile phone

2.1k Views Asked by At

I am working on a site and working on a component that will take users using wap or xhtml-mp and redirect them to sites specifically setup for those devices. Is there a good standard way of detecting which of these the user is using?

4

There are 4 best solutions below

0
masukomi On BEST ANSWER

Because no matter what you do you WILL get it wrong sooner or later, each version of the site should include a link to a page where the user can choose an appropriate format. Once they chose, cookie them and, if present, use that cookie as an override to whatever user-agent sniffing would have told you.

In addition to user agent sniffing if your site involves logging in you can store that preference permanently and re-cookie them, if needed, upon login. If it's obvious from the user agent string just use that, if it's not, ask them to choose from a list of your available options and store their choice as the default.

1
Joel Coehoorn On

There's always the User Agent string. But that means keeping up with all the latest browsers, and differentiating between them isn't always simple.

Instead of redirecting to a completely different page, try using a media selector in your style sheets to tweak your normal content for the smaller screen.

0
Joachim Sauer On
0
fravelgue On

Check this and WURFL.