摘要:我们使用的来获取手机用户浏览器的用户代理,然后匹配已有的各种手机浏览器代理库,如果含有匹配的关键字,则判断为手机移动终端用户。使用时只需调用函数。如以下代码表示,当匹配用户为手机访问时,页面跳转到网站手机版
我们使用PHP的$_SERVER["HTTP_USER_AGENT"]来获取手机用户浏览器的用户代理,然后匹配已有的各种手机浏览器代理库,如果含有匹配的关键字,则判断为手机(移动终端)用户。
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","iphone","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");
$is_mobile = false;
foreach ($mobile_agents as $device) {
if (stristr($user_agent, $device)) {
$is_mobile = true;
break;
}
}
return $is_mobile;
}
上述代码中函数is_mobile()来判断用户终端类型,将收集到的当今各种手机的HTTP_USER_AGENT归结到数组$mobile_agents中,并进行匹配。使用时只需调用函数is_mobile()。如以下代码表示,当匹配用户为手机访问时,页面跳转到网站手机版
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/20655.html
摘要:人生中的每一件事都取决于我们自己的时间,你身边有些朋友也许遥遥领先于你,有些朋友也许落后于你,但凡事都有它自己的节奏因此,无论当下如何,保持一颗平静的心,从容对待。愿你始终相信,一切都会准时到来的。不言而喻的是信心对完成任务的作用很大。 《别让任何人打乱你的生活节奏》完美人生 就是 18岁成人 22岁大学毕业,25岁工作稳定,30岁之前买房结婚生子,35岁之后人生轨迹就会定型…… 可是...
摘要:十年,转瞬即逝,人生进入下半场。没想到,公司在短短年时间里就上市了,作为头部员工,他获得了不菲的回报。他其实挺喜欢写代码的,但程序员工资还是低了点。就像养狗一样,要有规矩。去年为了还贷款,还变卖了一套。 风险预警。本文属于毒鸡汤系列,经过文学渲染,读后或产生焦虑,有相关抵制者慎入。 十年,转瞬即逝,人生进入下半场。众生皆苦,万相本无。且看风云变幻,慢品苦辣酸甜。小姐姐味道微信公众号首发。 ...
阅读 1533·2021-11-23 09:51
阅读 1076·2021-10-12 10:12
阅读 2793·2021-09-22 16:06
阅读 3604·2019-08-30 15:56
阅读 3428·2019-08-30 15:53
阅读 3083·2019-08-29 16:29
阅读 2330·2019-08-29 15:27
阅读 2001·2019-08-26 10:49