日韩精品成人无码专区免费-国产99久久久久久免费看-国产精品丝袜久久久久久不卡-国产精品无码一区二区三区

PHP如何判斷是手機還是PC?

發布時間:2024-07-09 點擊:261
php如何判斷是手機還是pc?
php判斷是手機還是pc的方法:首先將取出“$_server['http_user_agent']”數據;然后使用正則匹配數據中是否有手機瀏覽器標識,如“mobile”、“wap”等;最后根據匹配結果即可判斷出是手機還是pc。
示例代碼
/*移動端判斷*/function ismobile(){ // 如果有http_x_wap_profile則一定是移動設備 if (isset ($_server['http_x_wap_profile'])) { return true; } // 如果via信息含有wap則一定是移動設備,部分服務商會屏蔽該信息 if (isset ($_server['http_via'])) { // 找不到為flase,否則為true return stristr($_server['http_via'], "wap") ? true : false; } // 腦殘法,判斷手機發送的客戶端標志,兼容性有待提高 if (isset ($_server['http_user_agent'])) { $clientkeywords = array ('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile' ); // 從http_user_agent中查找手機瀏覽器的關鍵字 if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_server['http_user_agent']))) { return true; } } // 協議法,因為有可能不準確,放到最后判斷 if (isset ($_server['http_accept'])) { // 如果只支持wml并且不支持html那一定是移動設備 // 如果支持wml和html但是wml在html之前則是移動設備 if ((strpos($_server['http_accept'], 'vnd.wap.wml') !== false) && (strpos($_server['http_accept'], 'text/html') === false || (strpos($_server['http_accept'], 'vnd.wap.wml') < strpos($_server['http_accept'], 'text/html')))) { return true; } } return false;}推薦教程:《php》

請開啟云服務器配置
用Node.js如何快速構建一個API服務器?
阿里云服務器購買優惠政策
電腦無法用QQ瀏覽器以外的瀏覽器打開QQ郵箱怎么解決
企業內部云服務器優惠購買
無憂云四川雅安高防服務器促銷
IBM將進一步加強與中國云服務廠商的合作-國外服務器托管
網站建設究竟有哪些作用引人向往