如果你的手机能翻墙,当你访问 http://zuo.la/ 和 http://www.zuola.com 的首页时,会看到不同的内容,怎么做到的?下面是代码,用来判断user agent的,希望对你有用。
重要的是,这段代码的版权不归我,是我从WordPress Mobile Edition 找出来的,单独拿出来用可以解决些简单的问题。
<?php
$mobile = array(
‘2.0 MMP’,
‘240×320’,
‘400X240’,
‘AvantGo’,
‘BlackBerry’,
‘Blazer’,
‘Cellphone’,
‘Danger’,
‘DoCoMo’,
‘Elaine/3.0’,
‘EudoraWeb’,
‘Googlebot-Mobile’,
‘hiptop’,
‘IEMobile’,
‘KYOCERA/WX310K’,
‘LG/U990’,
‘MIDP-2.’,
‘MMEF20’,
‘MOT-V’,
‘NetFront’,
‘Newt’,
‘Nintendo Wii’,
‘Nitro’, // Nintendo DS
‘Nokia’,
‘Opera Mini’,
‘Palm’,
‘PlayStation Portable’,
‘portalmmm’,
‘Proxinet’,
‘ProxiNet’,
‘SHARP-TQ-GX10’,
‘SHG-i900’,
‘Small’,
‘SonyEricsson’,
‘Symbian OS’,
‘SymbianOS’,
‘TS21i-10’,
‘UP.Browser’,
‘UP.Link’,
‘webOS’, // Palm Pre, etc.
‘Windows CE’,
‘WinWAP’,
‘YahooSeeker/M1A1-R2D2’,
);
$touch = array(
‘iPhone’,
‘iPod’,
‘Android’,
‘BlackBerry9530’,
‘LG-TU915 Obigo’, // LG touch browser
‘LGE VX’,
‘webOS’, // Palm Pre, etc.
‘Nokia5800’,
);$browsers = array_merge($touch, $mobile);
foreach ($browsers as $browser) {
if (!empty($browser) && strpos($_SERVER[“HTTP_USER_AGENT”], trim($browser)) !== false) {
$mobile = true;
include_once(‘mobile.php’); // mobile version page,replace file name here
exit;
}
}readfile(‘html.htm’); // normal version page, repleace file name here
exit;
?>
Dabr 也是这么实现的,沙发一下~