摘要:我們使用的來獲取手機用戶瀏覽器的用戶代理,然后匹配已有的各種手機瀏覽器代理庫,如果含有匹配的關鍵字,則判斷為手機移動終端用戶。使用時只需調用函數。如以下代碼表示,當匹配用戶為手機訪問時,頁面跳轉到網站手機版
我們使用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()。如以下代碼表示,當匹配用戶為手機訪問時,頁面跳轉到網站手機版
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/20655.html
摘要:人生中的每一件事都取決于我們自己的時間,你身邊有些朋友也許遙遙領先于你,有些朋友也許落后于你,但凡事都有它自己的節奏因此,無論當下如何,保持一顆平靜的心,從容對待。愿你始終相信,一切都會準時到來的。不言而喻的是信心對完成任務的作用很大。 《別讓任何人打亂你的生活節奏》完美人生 就是 18歲成人 22歲大學畢業,25歲工作穩定,30歲之前買房結婚生子,35歲之后人生軌跡就會定型…… 可是...
摘要:十年,轉瞬即逝,人生進入下半場。沒想到,公司在短短年時間里就上市了,作為頭部員工,他獲得了不菲的回報。他其實挺喜歡寫代碼的,但程序員工資還是低了點。就像養狗一樣,要有規矩。去年為了還貸款,還變賣了一套。 風險預警。本文屬于毒雞湯系列,經過文學渲染,讀后或產生焦慮,有相關抵制者慎入。 十年,轉瞬即逝,人生進入下半場。眾生皆苦,萬相本無。且看風云變幻,慢品苦辣酸甜。小姐姐味道微信公眾號首發。 ...
閱讀 1571·2021-11-23 09:51
閱讀 1107·2021-10-12 10:12
閱讀 2826·2021-09-22 16:06
閱讀 3651·2019-08-30 15:56
閱讀 3477·2019-08-30 15:53
閱讀 3122·2019-08-29 16:29
閱讀 2372·2019-08-29 15:27
閱讀 2031·2019-08-26 10:49