现在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()) {