當前位置:首頁 » 編程語言 » wapphp

wapphp

發布時間: 2024-06-23 02:56:41

php如何判斷用戶通過手機wap訪問還是電腦直接訪問

PHP通過內置全局變數$_SERVER['HTTP_USER_AGENT']來獲取用戶信息,包括瀏覽器信息,操作系統等;判斷是否是手機還是電腦終端訪問,只需判斷他的$_SERVER['HTTP_USER_AGENT']信息是否存在手機終端類型即可。示例如下:
<?php
//1.獲取用戶瀏覽器信息 等;
$user_agent = $_SERVER['HTTP_USER_AGENT'];

//2.列舉常用手機終端類型
$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");

foreach ($mobile_agents as $device) {
if (stristr($user_agent, $device)) {
//手機訪問
$is_mobile = true;
break;
}
}
//判斷手機標識是否為真
if($is_mobile){
echo "手機訪問!";
}else{
echo "電腦訪問!";
}

?>

回答不容易,希望能幫到您,滿意請幫忙採納一下,謝謝 !

Ⅱ 請教大神,php網址參數是怎麼傳遞的

wap.php這個文件叫做單入口文件,就是指所有的文件都要從這個文件進入,參數是等號後面的這個字元串,例如:一般都是通過$_GET['c']的到Group的,c一般是定義了你的文件夾,a一般是定義了你的文件名,也就是Group文件下的index文件

熱點內容
漏油器密碼怎麼改密碼 發布:2024-11-26 20:30:11 瀏覽:13
linux編碼命令 發布:2024-11-26 20:23:13 瀏覽:800
密碼加密工具 發布:2024-11-26 20:23:06 瀏覽:691
如何破解加密的wifi 發布:2024-11-26 20:10:29 瀏覽:430
c腳本檢查 發布:2024-11-26 19:56:34 瀏覽:393
伺服器ip控制系統叫什麼 發布:2024-11-26 19:56:31 瀏覽:746
ecshop文件夾許可權 發布:2024-11-26 19:55:05 瀏覽:73
編程123 發布:2024-11-26 19:52:52 瀏覽:949
python數組排序排序演算法 發布:2024-11-26 19:50:16 瀏覽:969
如保編程 發布:2024-11-26 19:29:58 瀏覽:812