歡迎來(lái)到奇迪科技(深圳)有限公司,超值服務(wù)提供卓越產(chǎn)品!
網(wǎng)站制作之判斷PC還是移動(dòng)客戶(hù)端_常見(jiàn)問(wèn)題_奇迪科技(深圳)有限公司(m.cheanjie.com)
現在手機網(wǎng)站和電腦PC網(wǎng)站制作,流行手機網(wǎng)站和電腦PC網(wǎng)站智能識別客戶(hù)端。自動(dòng)識別訪(fǎng)問(wèn)網(wǎng)站的客戶(hù)端,自動(dòng)打開(kāi)相應的網(wǎng)頁(yè)。
PHP實(shí)現的自動(dòng)識別功能代碼如下:
* +---------------------------------------------------------- * 判斷是否是移動(dòng)客戶(hù)端 * +---------------------------------------------------------- */ function is_mobile() { static $is_mobile; $user_agent = $_SERVER['HTTP_USER_AGENT']; if (isset($is_mobile)) return $is_mobile; if (empty($user_agent)) { $is_mobile = false; } else { // 移動(dòng)端UA關(guān)鍵字 $mobile_agents = array ( 'Mobile', 'Android', 'Silk/', 'Kindle', 'BlackBerry', 'Opera Mini', 'Opera Mobi' ); $is_mobile = false; foreach ($mobile_agents as $device) { if (strpos($user_agent, $device) !== false) { $is_mobile = true; break; } } } return $is_mobile; }
上面這段代碼是一個(gè)自定義函數,適用于使用PHP網(wǎng)站建設的朋友們,其功能主要是根據UA關(guān)鍵字來(lái)判斷、確認訪(fǎng)問(wèn)的客戶(hù)端是移動(dòng)設備還是電腦PC設備。
本文版權所有,轉載須注明:來(lái)源 http://m.cheanjie.com/qvdv-fqa-642.html