PHP judges two instances. one is PHP's judgment on the mobile phone or PC, and the other is PHP's judgment on whether it is a browser for your reference, the specific content is as follows. here, the blogger shares two PHP judgment instances. one is PHP's judgment on the mobile phone or PC, and the other is PHP's judgment on whether it is a browser for your reference, the details are as follows:
1. determine whether it is a mobile phone
Function isMobile () {// if there is HTTP_X_WAP_PROFILE, it must be a mobile device if (isset ($ _ SERVER ['http _ X_WAP_PROFILE ']) {return true ;} // if the via information contains wap, it must be a mobile device. some service providers will block this information if (isset ($ _ SERVER ['http _ VE']) {// cannot be found as flase; otherwise, it is true return stristr ($ _ SERVER ['http _ vean'], "wap ")? True: false;} // identify the client flag sent by the mobile phone. the compatibility needs to be improved. Here, 'micromessenger 'is the computer if (isset ($ _ SERVER ['http _ USER_AGENT']) {$ clientkeywords = array ('Nokia ', 'Sony', 'ericsson ', 'MOT', 'Samsung ', 'HTC', 'sgh', 'LG ', 'sharp', 'sie-', 'Philips', 'panasonic ', 'alcatel', 'Lenovo ', 'iPhone', 'iPod ', 'BlackBerry', 'meizu', 'Android', 'netfront', 'symbian ', 'ucweb ', 'windowsce ', 'Palm', 'operamini ', 'operamobi', 'openwave', 'nexusone', 'cldc ', 'midp', 'wap ', 'mobile ', 'micromessenger '); // from HTT Search for the keyword if (preg_match ("/(". implode ('|', $ clientkeywords ). ")/I", strtolower ($ _ SERVER ['http _ USER_AGENT ']) {return true ;}// resolution method, because it may be inaccurate, put it at the end to determine if (isset ($ _ SERVER ['http _ ACCEPT ']) {// if only wml is supported and html is not supported, it must be a mobile device // if wml and html are supported, but wml is a mobile device before html (strpos ($ _ SERVER ['http _ ACCEPT '], 'vnd. wap. wml ')! = False) & (strpos ($ _ SERVER ['http _ ACCEPT '], 'text/html ') === false | (strpos ($ _ SERVER ['http _ ACCEPT '], 'vnd. wap. wml ') <strpos ($ _ SERVER ['http _ ACCEPT'], 'text/html ') {return true ;}} return false ;}
2. determine whether it is a built-in browser
function isWeixin() { if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) { return true; } else { return false; }}
The above is the details about PHP's mobile phone, PC, and sample code sharing. For more information, see other related articles in the first PHP community!