當前位置:首頁 » 編程語言 » 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文件

熱點內容
iptables限制ip訪問 發布:2025-01-17 21:38:01 瀏覽:174
易拉罐壓縮機 發布:2025-01-17 21:25:35 瀏覽:924
在c語言是什麼意思啊 發布:2025-01-17 21:21:02 瀏覽:516
re0腳本 發布:2025-01-17 21:13:34 瀏覽:305
甜蜜家園密碼箱有什麼用 發布:2025-01-17 21:07:28 瀏覽:48
有教少兒編程 發布:2025-01-17 20:55:37 瀏覽:37
直播背腳本 發布:2025-01-17 20:50:18 瀏覽:410
ftp移動文件的mv命令 發布:2025-01-17 20:45:53 瀏覽:405
電腦上啥是伺服器 發布:2025-01-17 20:40:48 瀏覽:353
安卓手機怎麼連大眾車載 發布:2025-01-17 20:20:53 瀏覽:241