PHP Judge Mobile Access Implementation program

Source: Internet
Author: User

Found on the Internet

Mobile phone access, the principle is mobile phone through the mobile company's proxy server access. Then we can understand that an ordinary computer uses a proxy server. When a mobile phone is accessed through a proxy server, the HTTP header information will undoubtedly contain a message: via. This information provides valuable judgment information.
For example, the Henan mobile obtained via information is:

http/1.1 Hazz-b-gw001-wap (INFOX-WISG, technologies)
The VIA information of Henan Unicom is:

Zxwap Gateway,zte Technologies

Code

The code is as follows Copy Code

Check if WAP by xhatfunction
Check_wap () {
Return Stristr ($_server[' Http_via '], "WAP")? True:false;
}

The result is that no one can fake a mobile phone interview, and the judgment is absolutely accurate. Naturally, this is the Internet's popular mobile WAP simulator has also been shielded-fundamentally shielded.
That's definitely not going to work.

I saw this one on the internet again.

PHP to judge the function of the mobile browser, code as follows, added to the ipad and Android judgment

The code is as follows Copy Code

<?php
//Check if WAP
function Check_wap () {
 if (stristr ($_server[' Http_via '], "WAP")) {//Check if WAP agent first, high accuracy
  return true;
 }elseif (Strpos strtoupper ($_server[' http_accept '), "VND. Wap. WML ") > 0) {//check whether the browser accepts WML.
  return true;
  }elseif (Preg_match ('/blackberry| CONFIGURATION/CLDC|HP |HP-|HTC |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera Mini|opera | googlebot-mobile| yahooseeker/m1a1-r2d2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh| Spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/I ', $_server[' http_user_agent ']) {//Check User_ AGENT
  return true;    
 }else{
  return false; 
   }
  
}

After the test is still a problem, do not say you know, and then saw the WordPress function.php file such a section

The code is as follows Copy Code

Determine whether it belongs to a mobile phone
function Is_mobile () {
$user _agent = $_server[' http_user_agent '];
  $mobile _agents = Array ("240x320", "Acer", "Acoon", "acs-", "Abacho", "Ahong", "Airness", "Alcatel", "Amoi", "" Android, "Anywhereyougo.com", "applewebkit/525", "applewebkit/532", "Asus", "Audio", "Au-mic", "Avantogo", "Becker", " BenQ "," Bilbo "," Bird "," BlackBerry "," blazer "," Bleu "," cdm-"," Compal "," Coolpad "," Danger "," Dbtel "," Dopod "," Elaine ", "Eric", "Etouch", "Fly", "Fly_", "fly-", "Go.web", "goodaccess", "Gradiente", "Grundig", "Haier", "Hedy", "Hitachi", "HTC" , "Hutchison", "Inno", "The ipad", "iPAQ", "ipod", "Jbrowser", "KDDI", "kgt", "KWC", "Lenovo", "LG", "Lg2", "Lg3", "Lg4 "," Lg5 "," Lg7 "," Lg8 "," Lg9 "," lg-"," lge-"," Lge9 "," Longcos "," Maemo "," Mercator "," Meridian "," Micromax "," MIDP "," Mini " , "Mitsu", "MMM", "MMP", "Mobi", "mot-", "Moto", "nec-", "NetFront", "Newgen", "Nexian", "Nf-browser", "Nintendo", "Nitro", "Nokia", "Nook", "Novarra", "Obigo", "Palm", "Panasonic", "Pantech", "Philips", "Phone", "pg-", "PlayStation", "Pocket", " Pt-"," qc-"," Qtek "," Rover "," Sagem "," sama "," Samu "," Sanyo "," Samsung "," sch-"," Scooter "," sec-"," Sendo "," sgh-"," Sharp "," Siemens"," sie-"," SoftBank "," Sony "," Spice "," Sprint "," SPV "," Symbian "," tablet "," Talkabout "," tcl-"," Teleca "," Telit "," Tianyu "," tim-"," Toshiba "," TSM "," Up.browser "," Utec "," Utstar "," Verykool "," Virgin "," vk-"," Voda "," Voxtel "," VX "," WAP "," Wellco "," Wig Browser "," Wii "," Windows CE "," wireless "," XDA "," Xde "," ZTE ");
$is _mobile = false;
foreach ($mobile _agents as $device) {
if (Stristr ($user _agent, $device)) {
$is _mobile = true;
Break
}
}
return $is _mobile;
}

Join in your Web

The code is as follows Copy Code

if (Is_mobile ()) {
Include (' Mobile Access. php file can '); exit;
}

There are many ways to solve such problems, if you do not want to do so can directly use the level two domain name.

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.