View Single Post
Old 05-03-2012, 03:35 AM  
benk81
Confirmed User
 
Industry Role:
Join Date: Dec 2010
Location: London
Posts: 191
I am attaching below a very basic code for how to detect mobile although there are far more possibilities.
Hope it helps?

<?php
/**
Use to loosely detect a mobile browser
No warranties or guarantees given. Not recomended for production environments.
Loosly Updated from: http://mobiforge.com/developing/stor...-detection-php
We recomend to use: http://wurfl.sourceforge.net/
**/

$MOBILE_BROWSER = 0;

if (preg_match('/(up.browser|up.link|mmp|symbian|midp|wap|phone|and roid|webos|blackberry|mobile|pocket|kindle|psp|mae mo|palm)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
$MOBILE_BROWSER++;
}

if (!$MOBILE_BROWSER && (
(strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or
(strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.wml') > 0) or
((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or
isset($_SERVER['HTTP_X_SKYFIRE_PHONE']) or isset($_SERVER['X_DEVICE_USER_AGENT']) or
isset($_SERVER['X_ORIGINAL_USER_AGENT']) or isset($_SERVER['X_MOBILE_UA'])))
)) {
$MOBILE_BROWSER++;
}

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
$mobile_agents = array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird' ,'blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','palm','pana','pant','phil','play',' port','prox','qwap',
'sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-',
'siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh',
'tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr',
'webc','winw','winw','xda ','xda-');
if (!$MOBILE_BROWSER && in_array($mobile_ua,$mobile_agents)) {
$MOBILE_BROWSER++;
}

if (!$MOBILE_BROWSER &&
(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'opera mini') > 0) or
(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'opera mobi') > 0) or
(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows ce') > 0) or
(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'novarra') > 0)
) {
$MOBILE_BROWSER++;
}

//Some custom code to deal with result
$REGULAR_URL = 'http://www.reporo.com';
$MOBILE_URL = 'http://m.reporo.com';
header('Location: ' . ($MOBILE_BROWSER?$MOBILE_URL:$REGULAR_URL));
__________________
benk81
ICQ 604 518 639
ben (at) reporo . com
benk81 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote