- If you have http_x_wap_profile, it must be a mobile device.
- if (Isset ($_server[' http_x_wap_profile ')) {
- return true;
- }
Copy CodeAnalysis: By getting the Http_x_wap_profile information returned by the client, it can be judged that it must be a mobile terminal, but not all mobile phones can return this information, this and wait for access via is the same, which involves terminal and service provider problems! Code:
- If the VIA message contains a WAP, it must be a mobile device, and some service providers block that information
- if (Isset ($_server[' Http_via '))
- {
- Not found for flase, otherwise true
- Return Stristr ($_server[' Http_via '), "WAP")? True:false;
- }
Copy CodeAnalysis: This http_via contains a service provider to provide some personal information, if judged by this is the most accurate, but for example, mobile blocking this information. Therefore, only some of the service providers are valid. Code:
- Brain residue method, determine the mobile phone to send the client logo, compatibility needs to be improved
- 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 ';
- Find keywords for your phone's browser from Http_user_agent
- if (Preg_match ("/(". Implode (' | '), $clientkeywords). ") /I ",
- Strtolower ($_server[' http_user_agent ')))
- {
- return true;
- }
- }
Copy CodeAnalysis: This uses the client return information [Http_user_agent] To configure the phone terminal keyword. Imagine, to list all the mobile phone identification, can be accurately judged, is this feasible? So, as long as the main list of mobile phone brands, so it is basically OK. However, in the code there is a judgment UCWeb, this is not judged. Because, I get the information and get the information of Firefox is consistent, also can't find UCWeb keyword. Therefore, the use of UCWeb browser can not be judged, waiting for new methods to appear. After all, UCWeb occupies the majority of users, but UCWeb is a PC browser standard, because some are mistaken for a PC browser can also! Code:
- Protocol law, because there may be inaccuracies, put to the final judgment
- 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
- if ((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;
- }
- }
Copy CodeAnalysis: At the end of the deal, there is no agreement. Is the MIME type to judge, only to receive WML pages of the phone, needless to say must be a mobile terminal, but such naïve idea is impossible. Because, now mobile phone can gradually and the function of the computer close!? The type of page that is acceptable on the browser is also not just wml,html supported. Receive WML in front of HTML, this can be said to be a phone, but not absolute. For example, the blueberry is the HTML row before, WML in the back. So you can't make a judgment. To summarize, write the following PHP Judgment page program.
- /**
- * Program: iswap.php to determine if it is accessed via mobile phone
- * Program returns: whether @return bool is a mobile device
- */
- function IsMobile ()
- {
- If you have http_x_wap_profile, it must be a mobile device.
- if (Isset ($_server[' http_x_wap_profile ')) {
- return true;
- }
- If the VIA message contains a WAP, it must be a mobile device, and some service providers block that information
- if (Isset ($_server[' Http_via '))
- {
- Not found for flase, otherwise true
- Return Stristr ($_server[' Http_via '), "WAP")? True:false;
- }
- Brain residue method, determine the mobile phone to send the client logo, compatibility needs to be improved
- 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 ';
- Find keywords for your phone's browser from Http_user_agent
- if (Preg_match ("/(". Implode (' | '), $clientkeywords). ") /I ",
- Strtolower ($_server[' http_user_agent ')))
- {
- return true;
- }
- }
- Protocol law, because there may be inaccuracies, put to the final judgment
- 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
- if ((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;
- }
- ?>
Copy Code |