views:

329

answers:

3

We have a site developed in PHP. It is working just fine. We have used JQuery for every kind of situation like slide shows, menus, etc.

This site contains a lot of images which are large in size. because of this when viewed in a mobile phone user has to scroll a lot.

How can we recognize whether the client (browser) trying to access our site is a mobile phone or a standard PC.

Is there any standard way to build site for such situations?

TIA

+5  A: 

you should check the user-agent header which is sent along the HTTP request. Since there are so many useragents, it's really difficult to recognize the various devices/platforms. For this purpose there is a freeware library which can help out : wurfl

Basically it maps the user-agent to a device object which you can query for it's capabilities. This way in your layout you can take advantage of the device's screenwidth/height, what image formats it supports, etc

Toad
+1  A: 

http://beradrian.wordpress.com/2008/10/10/mobile-device-recognition/

Jim Blackler
Thanks for the link. I will check it out and get back if required.
Yogi Yang 007
+2  A: 

You should look at Tera-WURFL, it is a PHP & MySQL-based software package that detects mobile devices and their capabilities. Here is the Tera-WURFL code that you would use to detect if a request is coming from a mobile device:

<?php
require_once("TeraWurfl.php");
$wurflObj = new TeraWurfl();
$wurflObj->GetDeviceCapabilitiesFromAgent();
if($wurflObj->capabilities['product_info']['is_wireless_device']){
    echo "This is a mobile device";
}else{
    echo "This is a desktop browser";
}
?>    
Steve Kamerman
Thanks for this lib pointer.It did the trick in the way I wanted it to do.
Yogi Yang 007