Starting > Designing > Developing > Testing > Running
Home | News | Blogs | About

Using PHP Header information for mobile detection

Hey everyone, I saw that no one has posted here yet, so i though this might be a good place to start :)
I have created a php based detection script for mobile sites. Most of the mobile sites I create are usually housed in a /mobile/ folder within the main site (long story... don't ask ;)). So if both sites are with in the same domain I thought i would be easy to detect whether the person visiting the site was either a computer or a mobile device. So here what I came up with:
Basically I do a preg_match search in the $_SERVER variable (remembering that this is php, asp and jsp are different).
preg_match(My pattern, $_SERVER array) -> so it likes this preg_match("/http_(x|ua)_.*?/Ai",$_SERVER)

The regular expression searches the array keys for anything that matchs HTTP_X_ or HTTP_UA_
Only mobile browsers will set a HTTP_X variables and only Windows Mobile devices will set the HTTP_UA variables.

So far this as proved to work for ever device I have tested, including Opera Mini which is gain great momentum in the mobile industry. Please let me know what you think, or if you have any questions... ask away!!

Cheers!

Switcher iconSwitch to our desktop site | mobiThinking