wapphp
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文件