找回密码
 立即注册

QQ登录

只需一步,快速开始

群里有朋友问我PHP判断手机端访问跳转到对应的域名的方法,下面提供两个

1、跳转到网址


//php判断客户端是否为手机
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($agent,"NetFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS"))
header("Location:http://wap.域名.com/");}



2、跳转到自定文件

if (isset ($_SERVER['HTTP_USER_AGENT'])) {
  $clientkeywords = array ('nokia',  'sony','ericsson','mot','samsung','htc','sgh','lg','sharp','oppo','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile');

// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))){
require_once 'm.php';
}else{
require_once 'pc.php';
}
}else{
echo "未知";
}

分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册