您的位置:首页 > 其它

辨别平台

2015-06-25 18:33 197 查看
//获得的信息
$headers = Yii::$app->request->headers;
$agent=$headers['user-agent'];
/**
* 分辨iOS Android  微信 微信分享到浏览器
*/
public static function getType($agent){
$ios = explode('iPhone',$agent);
$android=explode('Android',$agent);
$weixin=explode('MicroMessenger',$agent);
//判断为iOS 安卓  type 1为iOS,2为Android,3为微信,
$type=0;
if(count($ios)>1){
$type=1;
}else if(count($android)>1&&empty(Yii::$app->request->get('from'))){
$type=2;
}else if(Yii::$app->request->get('from')&&count($weixin)>1){
//在微信中打开
$type=3;
}else if(Yii::$app->request->get('from')&&count($weixin)<=1&&count($ios)>1){
//微信中分享到浏览器ios平台
$type=1;
}else if(Yii::$app->request->get('from')&&count($weixin)<=1&&count($android)>1){
//微信中分享到浏览器 安卓平台
$type=2;
}

return $type;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: