php判断是手机端或者PC端,并跳转不同页面

php判断是手机端或者PC端,并跳转不同页面的方法和代码如下所示:

<?php
//正则表达式,批配不同手机浏览器UA关键词,如果UA中存在上面的关键词则返回真。
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']));}
if(is_mobile()) {     
//如果为真,则进行WAP页面。       
header( "HTTP/1.1 301 Moved Permanently");         
header("Location: http://");     
}
else {         
//如果为假,则进行WEB页面。        
header( "HTTP/1.1 301 Moved Permanently");         
header("Location: http://");      
} ?>

猜你喜欢
刮毛器的正确方法 刮毛器的正确方法与步骤
苹果手机充不进去电是怎么回事啊 苹果手机充不进去电是什么原因
梦见蟒蛇什么意思 做梦梦见蟒蛇什么意思
醋熏房间有杀菌作用吗 室内熏醋能杀菌吗
2022年红石林景区门票免费吗 2021国庆石林风景区门票价格
腌鸭蛋的配方 保证鸭蛋出油率超高还不咸
扬州名菜有什么 扬州名菜有什么特点
卤肉冷水下锅还是热水 卤肉焯水是冷水下锅还是热水下锅
海螺开锅煮几分钟能熟 海螺煮几分钟能煮熟
草莓酱熬多长时间 草莓酱熬多长时间好

很赞哦! ()