PHP script to detect handheld devices

Associate
Joined
2 Aug 2005
Posts
680
Hi,

Does anyone know of a way to use PHP to detect if a browser is a handheld, and if so direct the browser to a different page (for example website/portabe) for a seperate portable version of the site?

I have added a CSS file with media="handheld" to make the current site compatable, but I want people on handhelds to access a different site with cut down content especially for people on the move.
 
Associate
Joined
30 Dec 2005
Posts
415
The only way i've seen this done so far is with libaries...but this seems as pain as they have to be reguarly updated, and could be missing browsers. Why can't there just be a header element which tells the server whether its a mobile or pc browser lol. Would be a lot easier!
 
Caporegime
Joined
18 Oct 2002
Posts
29,491
Location
Back in East London
buld yourself an array of known handheld user-agents and then use:

Code:
<?php

$array = array(/* known hand held user agent strings go here */);

if (in_array($_SERVER['HTTP_USER_AGENT'], $array)) {
    header('Location: http://www.yoursite.com/handheldpage.php');
}

?>
For a quick and easy answer.
 
Back
Top Bottom