PHP识别用户是通过手机浏览器、安卓app还是苹果app访问网站

现在pc已经没有多少流量了,需要尽量将用户往移动版引,同时需将通过手机浏览器访问的用户转化成app用户。

// 识别是否无线访问
function is_mobile()
{
$user_agent = $SERVER[‘HTTP_USER_AGENT’];
$mobile_agents = Array(“240x320”, “acer”, “acoon”, “acs-”, “abacho”, “ahong”, “airness”, “alcatel”, “amoi”, “android”, “anywhereyougo.com”, “applewebkit/525”, “applewebkit/532”, “asus”, “audio”, “au-mic”, “avantogo”, “becker”, “benq”, “bilbo”, “bird”, “blackberry”, “blazer”, “bleu”, “cdm-”, “compal”, “coolpad”, “danger”, “dbtel”, “dopod”, “elaine”, “eric”, “etouch”, "fly ", "fly
", “fly-”, “go.web”, “goodaccess”, “gradiente”, “grundig”, “haier”, “hedy”, “hitachi”, “htc”, “huawei”, “hutchison”, “inno”, “ipad”, “ipaq”, “ipod”, “jbrowser”, “kddi”, “kgt”, “kwc”, “lenovo”, "lg ", “lg2”, “lg3”, “lg4”, “lg5”, “lg7”, “lg8”, “lg9”, “lg-”, “lge-”, “lge9”, “longcos”, “maemo”, “mercator”, “meridian”, “micromax”, “midp”, “mini”, “mitsu”, “mmm”, “mmp”, “mobi”, “mot-”, “moto”, “nec-”, “netfront”, “newgen”, “nexian”, “nf-browser”, “nintendo”, “nitro”, “nokia”, “nook”, “novarra”, “obigo”, “palm”, “panasonic”, “pantech”, “philips”, “phone”, “pg-”, “playstation”, “pocket”, “pt-”, “qc-”, “qtek”, “rover”, “sagem”, “sama”, “samu”, “sanyo”, “samsung”, “sch-”, “scooter”, “sec-”, “sendo”, “sgh-”, “sharp”, “siemens”, “sie-”, “softbank”, “sony”, “spice”, “sprint”, “spv”, “symbian”, “tablet”, “talkabout”, “tcl-”, “teleca”, “telit”, “tianyu”, “tim-”, “toshiba”, “tsm”, “up.browser”, “utec”, “utstar”, “verykool”, “virgin”, “vk-”, “voda”, “voxtel”, “vx”, “wap”, “wellco”, “wig browser”, “wii”, “windows ce”, “wireless”, “xda”, “xde”, “zte”);
i s m o b i l e = f a l s e ; f o r e a c h ( is_mobile = false; foreach ( ismobile=false;foreach(mobile_agents as KaTeX parse error: Expected '}', got 'EOF' at end of input: … if (stristr(user_agent, $device)) {
$is_mobile = true;
break;
}
}
return $is_mobile;
}

// 识别app
function is_app()
{
$user_agent = $_SERVER[‘HTTP_USER_AGENT’];
$is_app = false;
a p p = s t r r p o s ( app=strrpos( app=strrpos(user_agent,“Html5Plus”);
if($app>0){
$is_app = true;
}
return $is_app;

}

// 识别android app
function is_android()
{
$user_agent = $_SERVER[‘HTTP_USER_AGENT’];
$mobile_agents = Array( “android” );
i s a n d r o i d = f a l s e ; f o r e a c h ( is_android = false; foreach ( isandroid=false;foreach(mobile_agents as KaTeX parse error: Expected '}', got 'EOF' at end of input: … if (stristr(user_agent, $device)) {
$is_android = true;
break;
}
}
return $is_android;

}

// 识别ios app
function is_ios()
{
$user_agent = $_SERVER[‘HTTP_USER_AGENT’];
$mobile_agents = Array( “iphone” , “ipad” );
i s i o s = f a l s e ; f o r e a c h ( is_ios = false; foreach ( isios=false;foreach(mobile_agents as KaTeX parse error: Expected '}', got 'EOF' at end of input: … if (stristr(user_agent, $device)) {
$is_ios = true;
break;
}
}
return $is_ios;

}

// php判断是无无线访问,则PC跳转到对应无线页面
if(is_mobile()) {
redirect(U(‘Mob/News/index’));
}

// 判断是不是app访问,如果不是则露出app下载链接,区分安卓app还是苹果app
if (!is_app()) {

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值