PHP determines whether it is a mobile phone or a PC. PHP determines whether it is a browser or a phppc.
The examples in this article share two examples of PHP judgment. One is PHP's judgment on the mobile phone or PC, and the other is PHP's judgment on whether the browser is used for your reference. The specific content is 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 HTTP _ 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 all the content of this article. I hope it will be helpful for your learning and support for helping customers.