- 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 via information contains WAP, it must be a mobile device, some service associations block this information
- if (isset ($_server[' Http_via ']))
- {
- //cannot be 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 the keywords in your phone 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;
- }
if ($this->ismobile ()) {//Jump to mobile page}else{//jump to PC-side page}
======================
First of all, a PHP lightweight identification class is recommended, Mobile-detect specifically identifies the mobile or PC-side access to the site, which can be based on the type of terminal access to the mobile browser or the Web site of the PC browser.
Mobile-detect website links are as follows Mobiledetect
The example links are as follows: Mobile-detect Example
Here is my simple to write the jump to the PC or mobile phone-side code:
[PHP]View PlainCopy
- <?php
- require_once ' mobile_detect.php '; //Note To introduce mobile_detect.php this class has a download link in the connection above
- $detect = new Mobile_detect;
- if ($detect->ismobile ()) {
- Header (' location:http://127.0.0.1/mobiledetect/mobiledetect/mobile.html ', true, 301);
- echo "mobile";
- }else{
- Header (' location:http://127.0.0.1/mobiledetect/mobiledetect/pc.html ', true, 301);
- echo "PC";
- }
- ?>
PHP to determine whether a visitor is a PC or a mobile terminal