Home > php教程 > php手册 > body text

php判断终端是手机还是电脑访问网站代码

WBOY
Release: 2016-06-21 08:49:23
Original
987 people have browsed it
<?php function check_wap() {  
    if (isset($_SERVER[&#39;HTTP_VIA&#39;])) return true;  
    if (isset($_SERVER[&#39;HTTP_X_NOKIA_CONNECTION_MODE&#39;])) return true;  
    if (isset($_SERVER[&#39;HTTP_X_UP_CALLING_LINE_ID&#39;])) return true;  
    if (strpos(strtoupper($_SERVER[&#39;HTTP_ACCEPT&#39;]),"VND.WAP.WML") > 0) {  
        // 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 Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');  
              
        $mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');  
              
        $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=0;$i<count if> 0){
			$flag = true;
			break;
		}
	}
	return $flag;
}

if(check_wap()){
	echo "wap";
}else{
echo "web";
}

?></count>
Copy after login



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template