熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

php判斷終端是手機還是電腦訪問網站代碼

2022-06-13   來源: PHP編程 

  <?php function check_wap() { if (isset($_SERVER[HTTP_VIA])) return true; if (isset($_SERVER[HTTP_X_NOKIA_CONNECTION_MODE])) return true; if (isset($_SERVER[HTTP_X_UP_CALLING_LINE_ID])) return true; if (strpos(strtoupper($_SERVER[HTTP_ACCEPT])"VNDWAPWML") > ) { // Check whether the browser/gateway says it accepts WML $br = "WML"; } else { $browser = isset($_SERVER[HTTP_USER_AGENT]) ? trim($_SERVER[HTTP_USER_AGENT]) : ; if(empty($browser)) return true; $mobile_os_list=array(Google Wireless TranscoderWindows CEWindowsCESymbianAndroidarmvlarmvMobileCentOSmowserAvantGoOpera MobiJME/MIDPSmartphoneGoWebPalmiPAQ); $mobile_token_list=array(Profile/MIDPConfiguration/CLDC×××××UPBrowserUPLinkSymbianOSPalmOSPocketPCSonyEricssonNokiaBlackBerryVodafoneBenQNovarraVisionIrisNetFrontHTC_Xda_SAMSUNGSGHWapakaDoCoMoiPhoneiPod); $found_mobile=checkSubstrs($mobile_os_list$browser) || checkSubstrs($mobile_token_list$browser); if($found_mobile) $br ="WML"; else $br = "WWW"; } if($br == "WML") { return true; } else { return false; } } function checkSubstrs($list$str){ $flag = false; for($i=;$i<count($list);$i++){ if(strpos($str$list[$i]) > ){ $flag = true; break; } } return $flag; } if(check_wap()){ echo "wap"; }else{ echo "web"; } ?>

  


From:http://tw.wingwit.com/Article/program/PHP/201311/21151.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.