1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| /**
* Indique si l'internaute courant est sur une plateforme mobile ou non
* @return boolean
*/
function isMobileBrowser() {
$mobileBrowser = array(
'Android',
'AvantGo',
'BlackBerry',
'DoCoMo',
'Fennec',
'iPod',
'iPhone',
'iPad',
'J2ME',
'MIDP',
'NetFront',
'Nokia',
'Opera Mini',
'Opera Mobi',
'PalmOS',
'PalmSource',
'portalmmm',
'Plucker',
'ReqwirelessWeb',
'SonyEricsson',
'Symbian',
'UP\\.Browser',
'webOS',
'Windows CE',
'Windows Phone OS',
'Xiino'
);
if (!isset($_SERVER['HTTP_USER_AGENT'])) {
return false;
}
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$pattern = '/' . implode('|', $mobileBrowser) . '/i';
return (bool) preg_match($pattern, $userAgent);
} |
Partager