Handset Detection in 2 easy steps.
August 20, 2008 – 12:20 amWe’ve had a few support emails over the last week or so with folks writing in to say ‘Looks Great, how do i get it working on my site’. So I’ve put together this little “How To” that should help to get you started.
- NOTE : For this How To you’ll need PHP on your web server.
1) Copy the script below into a file called redirect.php
2) Open that up in your fav text editor. We need to make a few changes.
Here’s the bits that need changing.
// Put Your API Key in Here
define(’APIKEY’,'00000000000000000000000000000000′);
// Put Your NON Mobile site homepage URL in here
define(’STDSITE’,'http://www.zaption.com’);
// Put your Mobile site URL in here
define(’MSITE’,'http://m.zaption.com’);
- Put your APIKEY from handsetdetection into top define (copy it over all those 0’s).
- Change the URL in STDSITE to your standard website.
- Change the URL in MSITE to your mobile site.
Bingo - Its all done - now you have a page which can do the detection and
redirect people to the most appropriate site for their device.
—————————————————————————————————
<?php
// HTTP/Request from PEAR.
include "HTTP/Request.php";
// Put Your API Key in Here
define('APIKEY','00000000000000000000000000000000');
// Put Your NON Mobile site homepage URL in here
define('STDSITE','http://www.zaption.com');
// Put your Mobile site URL in here
define('MSITE','http://www.handsetdetection.com');
// This is the handset detection server to query - No change needed here.
define('HD_SERVER','http://c1.handsetdetection.com');
function sendjson($data, $url) {
$tmp = json_encode($data);
$req =& new HTTP_Request($url);
$req->addHeader("Content-Type", "application/json");
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addRawPostData($tmp);
$req->sendRequest();
$reply = $req->getResponseBody();
return json_decode($reply, true);
}
function doDetect() {
$options = array('geoip', 'product_info');
$data = array();
$data['apikey'] = APIKEY;
// Pick up user agent from headers passed to the server
$data['User-Agent'] = $_SERVER['HTTP_USER_AGENT'];
$data['ipaddress'] = $_SERVER['REMOTE_ADDR'];
// Passing $_SERVER options in is optional.
$data = array_merge ($data, $_SERVER);
$result = sendjson($data, HD_SERVER."/devices/detect.json");
return $result;
}
$ret = doDetect();
if ($ret['message'] == 'OK') {
header('Location: '.MSITE);
} else {
header('Location: '.STDSITE);
}
?>

2 Responses to “Handset Detection in 2 easy steps.”
hi,
it didnt worked for me.
infact i would need to found if the device is wap2 enabled or not.
case 1: is not mobile = my www domain
case 2: support wap2 = my wap2 domain
case 3: dont support wap2 = my wap domain
kind regards,
By jaime on Nov 18, 2008
Hi Jaime,
Thanks for trying our service.
When you say ‘It didnt work’ - Do you mean that you had problems using the API ?
Cheers
r
By admin on Nov 18, 2008