摘要:我們使用的來獲取手機用戶瀏覽器的用戶代理,然后匹配已有的各種手機瀏覽器代理庫,如果含有匹配的關(guān)鍵字,則判斷為手機移動終端用戶。使用時只需調(diào)用函數(shù)。如以下代碼表示,當匹配用戶為手機訪問時,頁面跳轉(zhuǎn)到網(wǎng)站手機版
我們使用PHP的$_SERVER["HTTP_USER_AGENT"]來獲取手機用戶瀏覽器的用戶代理,然后匹配已有的各種手機瀏覽器代理庫,如果含有匹配的關(guān)鍵字,則判斷為手機(移動終端)用戶。
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;
}
上述代碼中函數(shù)is_mobile()來判斷用戶終端類型,將收集到的當今各種手機的HTTP_USER_AGENT歸結(jié)到數(shù)組$mobile_agents中,并進行匹配。使用時只需調(diào)用函數(shù)is_mobile()。如以下代碼表示,當匹配用戶為手機訪問時,頁面跳轉(zhuǎn)到網(wǎng)站手機版
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/20655.html
摘要:也正因為這個閉包的特性,閉包函數(shù)可以讓父函數(shù)的數(shù)據(jù)一直駐留在內(nèi)存中保存,從而這也是后來模塊化的基礎(chǔ)。只有閉包函數(shù),可以讓它的父函數(shù)作用域永恒,像全局作用域,一直在內(nèi)存中存在。的本質(zhì)就是如此,每個模塊文件就是一個大閉包。 為什么會有閉包 js之所以會有閉包,是因為js不同于其他規(guī)范的語言,js允許一個函數(shù)中再嵌套子函數(shù),正是因為這種允許函數(shù)嵌套,導致js出現(xiàn)了所謂閉包。 function...
摘要:人生中的每一件事都取決于我們自己的時間,你身邊有些朋友也許遙遙領(lǐng)先于你,有些朋友也許落后于你,但凡事都有它自己的節(jié)奏因此,無論當下如何,保持一顆平靜的心,從容對待。愿你始終相信,一切都會準時到來的。不言而喻的是信心對完成任務的作用很大。 《別讓任何人打亂你的生活節(jié)奏》完美人生 就是 18歲成人 22歲大學畢業(yè),25歲工作穩(wěn)定,30歲之前買房結(jié)婚生子,35歲之后人生軌跡就會定型…… 可是...
摘要:十年,轉(zhuǎn)瞬即逝,人生進入下半場。沒想到,公司在短短年時間里就上市了,作為頭部員工,他獲得了不菲的回報。他其實挺喜歡寫代碼的,但程序員工資還是低了點。就像養(yǎng)狗一樣,要有規(guī)矩。去年為了還貸款,還變賣了一套。 風險預警。本文屬于毒雞湯系列,經(jīng)過文學渲染,讀后或產(chǎn)生焦慮,有相關(guān)抵制者慎入。 十年,轉(zhuǎn)瞬即逝,人生進入下半場。眾生皆苦,萬相本無。且看風云變幻,慢品苦辣酸甜。小姐姐味道微信公眾號首發(fā)。 ...
閱讀 1558·2021-11-23 09:51
閱讀 1092·2021-10-12 10:12
閱讀 2811·2021-09-22 16:06
閱讀 3636·2019-08-30 15:56
閱讀 3458·2019-08-30 15:53
閱讀 3110·2019-08-29 16:29
閱讀 2361·2019-08-29 15:27
閱讀 2017·2019-08-26 10:49