Access to websites through mobile phones is becoming more and more popular. if we want to count the traffic of websites through PCs and mobile terminals, or we need to do some special processing for mobile terminals, then we need to identify the client of the user accessing the website. The following example uses php to identify whether the user accesses the website through a computer or a mobile phone. & Lt ;? PhpfunctionisMobile () {$ useragentisset, or if you need to do some special processing for the mobile terminal, then we need to identify the client of the user accessing the website, the following example uses php to identify whether a user accesses a website on a computer or on a mobile phone.
Function isMobile (){
$ Useragent = isset ($ _ SERVER ['http _ USER_AGENT '])? $ _ SERVER ['http _ USER_AGENT ']: '';
$ Useragent_commentsblock = preg_match ('| \(.*? \) | ', $ Useragent, $ matches)> 0? $ Matches [0]: '';
$ 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 ');
$ Found_mobile = CheckSubstrs ($ mobile_ OS _list, $ useragent_commentsblock) | CheckSubstrs ($ mobile_token_list, $ useragent );
If ($ found_mobile ){
Return true;
} Else {
Return false;
}
}
Function CheckSubstrs ($ substrs, $ text ){
Foreach ($ substrs as $ substr ){
If (false! = Strpos ($ text, $ substr )){
Return true;
}
Return false;
}
}
If (isMobile ()){
Echo 'log on to m.phpernote.com on the mobile phone ';
} Else {
Echo 'log on to www.phpernote.com 'on your computer ';
}