自动判断客户端使用不同接口

/ 0评 / 0

直接上代码

<?php
//在底部下改接口
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$is_pc = (strpos($agent, 'windows nt')) ? true : false;
$is_mac = (strpos($agent, 'mac os')) ? true : false;
$is_iphone = (strpos($agent, 'iphone')) ? true : false;
$is_android = (strpos($agent, 'android')) ? true : false;
$is_ipad = (strpos($agent, 'ipad')) ? true : false;        
if($is_pc){            
   $a=1;
}        
if($is_mac){              
   $a=1;
}        
if($is_iphone){              
   $a=2;
}        
if($is_android){              
   $a=2;
}        
if($is_ipad){              
   $a=2;
}
if($a==1){
	if($_GET['url']){
	$url=$_GET['url'];
	header("Location: 【电脑端接口】$url"); //例如http://pc.xxx.com 没有【】
	}
}
if($a==2){
	if($_GET['url']){
	$url=$_GET['url'];
	header("Location: 【手机端接口】=$url"); //例如http://m.xxx.com 没有【】
	}
}

发表评论

邮箱地址不会被公开。 必填项已用*标注