The code is as follows |
Copy Code |
$uAgent = $_server[' http_user_agent ']; $osPat = "mozilla|m3gate|winwap|openwave| Windows nt| Windows 3.1|95| blackcomb|98| me| X window|ubuntu| longhorn| Aix| Linux| amigaos| beos| Hp-ux| openbsd| freebsd| netbsd| os/2| osf1| SUN "; if (Preg_match ("/($osPat)/i", $uAgent))//winwap A browser that simulates WAP mobile internet; Openwave| back to the PC operating system { echo "Computer access"; } Else { echo "Mobile Access"; } Echo ' <br/> '. $uAgent; |
Now we're going to complete the case as a document.
The code is as follows |
Copy Code |
$ua = Strtolower ($_server[' http_user_agent ')); $uachar = "/(NOKIA|SONY|ERICSSON|MOT|SAMSUNG|SGH|LG|PHILIPS|PANASONIC|ALCATEL|LENOVO|CLDC|MIDP|MOBILE|WAP)/I"; if ($ua = = ' | | preg_match ($UACHAR, $ua)) &&!strpos (Strtolower ($_server[' Request_uri ')), ' WAP ') { $Loaction = ' wap/'; if (!empty ($Loaction)) { Ecs_header ("Location: $Loactionn"); Exit } } /** * Custom header function to filter for possible security risks * * @param string string content * * @return void **/ function Ecs_header ($string, $replace = True, $http _response_code = 0) { if (Strpos ($string, '.. /upgrade/index.php ') = = = 0) { Echo ' <script type= ' Text/javascript ">window.location.href=". $string. ';</script> '; } $string = Str_replace (Array ("R", "N"), Array (', '), $string);
if (Preg_match ('/^s*location:/is ', $string)) { @header ($string. "N", $replace);
Exit (); }
if (Emptyempty ($http _response_code) | | php_version < ' 4.3 ') { @header ($string, $replace); } Else { @header ($string, $replace, $http _response_code); } } |
JavaScript uses navigator.useragent to get it, but a non-intelligent machine does not seem to support JS.
JS-enabled mobile clients can also use the following code simple to determine whether the Windows computer access
The code is as follows |
Copy Code |
if (navigator.platform.indexOf (' Win32 ')!=-1) { Go to PC }else{ Go to Phone } |
More about judging Mobile Access articles http://www.111cn.net/phper/php-cy/44574.htm