在做織夢項目的時候,經常遇到手機端判斷的問題,大多數用js來判斷,但是會出現延遲問題,于是從php腳本入手,通過php代碼來判斷客戶端是否為手機端,這樣速度就會很快。下面是php代碼:
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|
alcatel|lenovo|cldc|midp|mobile)/i";
if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
$Loaction = 'm/';
if (!empty($Loaction))
{
header("Location: $Loaction\n");
exit;
}
}