PHP to judge the computer access, Mobile Access Example _php Tutorial

Source: Internet
Author: User
So I study how to use PHP to determine whether the Web is a computer access or mobile phone access, and then to load different CSS to achieve the phone and the computer can be normal access to the effect.

Web site looked up a lot of information, and finally found a suitable, more useful code, but also hope to give you a reference.
Copy the Code code as follows:

function Check_wap () {
if (Isset ($_server[' Http_via ')) return true;
if (Isset ($_server[' Http_x_nokia_connection_mode ')) return true;
if (Isset ($_server[' http_x_up_calling_line_id ')) return true;
if (Strpos (Strtoupper ($_server[' http_accept ')), "VND. Wap. WML ") > 0) {
Check whether the Browser/gateway says it accepts WML.
$BR = "WML";
} else {
$browser = isset ($_server[' http_user_agent ')? Trim ($_server[' http_user_agent '): ";
if (empty ($browser)) return true;
$mobile _os_list=array (' Google Wireless transcoder ', ' Windows CE ', ' windowsce ', ' Symbian ', ' Android ', ' armv6l ', ' armv5 ', ' Mobile ', ' CentOS ', ' mowser ', ' AvantGo ', ' Opera Mobi ', ' J2ME/MIDP ', ' Smartphone ', ' go.web ', ' Palm ', ' IPAQ ');

$mobile _token_list=array (' PROFILE/MIDP ', ' configuration/cldc-', ' 160x160 ', ' 176x220 ', ' 240x240 ', ' 240x320 ', ' 320x ' Up. ' Browser ', ' up. Link ', ' SymbianOS ', ' 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, $browser) | |
Checksubstrs ($mobile _token_list, $browser);
if ($found _mobile)
$BR = "WML";
else $BR = "WWW";
}
if ($br = = "WML") {
return true;
} else {
return false;
}
}

function Checksubstrs ($list, $str) {
$flag = false;
for ($i =0; $i<>
if (Strpos ($str, $list [$i]) > 0) {
$flag = true;
Break
}
}
return $flag;
}

if (Check_wap ()) {
echo "WAP";
}else{
echo "Web";
}

?>

The small series has been tested, can be identified as a computer access or mobile phone access.

http://www.bkjia.com/PHPjc/768127.html www.bkjia.com true http://www.bkjia.com/PHPjc/768127.html techarticle so I study how to use PHP to determine whether the Web is a computer access or mobile phone access, and then to load different CSS to achieve the phone and the computer can be normal access to the effect. Website ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.