PHP determines whether to log on to the mobile phone based on $ _ SERVER ['http _ USER_AGENT ']. it returns the proxy information that the user accesses the page. By referring to the network, my processing is as follows:/*** determine whether a string contains a certain value *@
PHP determines whether to log on to the mobile phone based on $ _ SERVER ['http _ USER_AGENT ']. it returns the proxy information that the user accesses the page. Refer to the network, my processing is as follows:
/*** Determine whether a string contains a certain value * @ Link http://www.phpddt.com */Function contains ($ str = '', $ search_str) {return strpos ($ str, $ search_str) === FALSE? FALSE: TRUE;}/*** determine mobile login */function is_mobilephone () {$ agent =$ _ SERVER ['http _ USER_AGENT ']; // $ keywords = array ("Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser "); $ mobile_ OS _list = array ('Google Wireless Transcoder ', 'windows CE', 'windowsce ', 'symbian', 'Android', 'armv6l', 'armv5 ', 'mobile ', 'cento', 'moyun', 'avantgo ', 'Opera Mobi', 'j2's/MIDP ', 'Smartphone', 'Go. web ', 'Palm', 'ipaq '); $ Mobile_token_list = array ('Profile/MIDP ', 'configuration/CLDC-', '000000', '000000', '000000', '000000 ', '1970*240 ', '1970*320', 'Up. browser ', 'Up. link ', 'symbian OS', 'palmos ', 'pocketpc', 'sonyericsson', 'Nokia ', 'BlackBerry', 'Vodafone', 'benq ', 'novarra-vision', 'Iris', 'netfront', 'HTC _ ', 'xda _', 'Samsung-sgh', 'wapaka ', 'docomo ', 'iPhone ', 'iPod'); $ mobile_list = array_merge ($ mobile_token_list, $ mobile_ OS _list); // exclude Windows if (! Contains ($ agent, "Windows NT") | (contains ($ agent, "Windows NT") & contains ($ agent, "compatible; MSIE "))) {// exclude Mac if (! Contains ($ agent, "Windows NT ")&&! Contains ($ agent, "Macintosh") {foreach ($ mobile_list as $ k => $ item) {if (contains ($ agent, $ item )) {return true ;}}} return false ;}
Even so, some mobile phones do not send UA messages, which may lead to incorrect judgment, but the chances are very small. after all, no one is using a smartphone now.