PHP判断是手机访问(wap)还是电脑访问(pc)
转载请注明本文链接:https://blog.l9s.cc/.html [生成短网址]
PHP判断是手机访问(wap)还是电脑访问(pc) 这里要修改第13行和16行 header("Location: http://".$_SERVER['HTTP_HOST']."/wap.php"); 13行是手机访问如果您需要他直接跳到某一个网站 不是自己程序的文件 那就写 header("Location: http://blog.l9s.cc/"); header("Location: http://".$_SERVER['HTTP_HOST']."/pc.php"); 16行是电脑访问如果你需要他直接掉到某一个网站,不是自己的某个文件那就这样改 header("Location: http://blog.l9s.cc");
<?php function is_mobile(){ $regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|"; $regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|"; $regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|"; $regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|"; $regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220"; $regex_match.=")/i"; return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT'])); } $is_mobile=is_mobile(); if($is_mobile){ header("Location: http://".$_SERVER['HTTP_HOST']."/wap.php"); //echo "http://".$_SERVER['HTTP_HOST']."/pc.php"; }else{ header("Location: http://".$_SERVER['HTTP_HOST']."/pc.php"); //echo "http://".$_SERVER['HTTP_HOST']."/pc.php"; } ?> |