How to determine whether a mobile phone or computer accesses the web

Source: Internet
Author: User
Tags perl script

Mobile devices are becoming more and more popular, and many websites are not particularly friendly to mobile phone access. Therefore, we need to allocate a web access interface for mobile phone customers. How can we determine whether a mobile phone or a computer is accessing it?

First, the user-agent information is sent along with the mobile phone number information. If we can get... Even if you use your toes, you will also think that this is your personal privacy information. Mobile and Unicom will certainly block or encrypt it. Unless your server IP address is on their whitelist.

In other ways, when the mobile phone is accessed through the proxy server, the http header will undoubtedly contain a message:. This information provides valuable judgment information.

For example:

The via information obtained by Henan mobile is:
Http/1.1 hazz-b-gw001-wap (infox-wisg, huawei technologies)
Henan Unicom's via information is:
Zxwap gateway, zte technologies

In this way, we can obtain the http via information string to see if it contains wap characters. If there is one, it is accessed through a mobile phone. This is very accurate, but it will also block users using mobile phone simulators (that is, using browsers that support wap )...

First read the code ====

check_wap() {       return stristr($_SERVER['HTTP_VIA'],"wap") ? true : false;  }  
Of course, the above method is too accurate. If we want to allow users who use mobile phone simulators to access it, we need to find another method.

The following is a method I can query on the Internet. by determining the browser proxy identifier and whether the browser supports WAP, I can determine whether to access the page. The disadvantage is that it is impossible to list all the mobile phone's browser identifiers and supported browser identifiers. All right...

Let's take a look at the code ====

  0) {          // Check whether the browser/gateway says it accepts WML.          $br = "WML";  
// The above return true is wap access} else {$ browser = isset ($ _ SERVER ['HTTP _ USER_AGENT '])? Trim ($ _ SERVER ['HTTP _ USER_AGENT ']): ''; if (empty ($ browser) return true; $ browser = substr ($ browser, 0, 4 ); if ($ browser = "Noki" | // Nokia phones and emulators $ browser = "Eric" | // Ericsson WAP phones and emulators $ browser = "WapI" | // Ericsson WapIDE 2.0 $ browser = "MC21" | // Ericsson MC218 $ browser = "AUR" | // Ericsson R320 $ browser = "R380" | // Ericsson R380 $ browser = "UP. B "| // UP. brows Er $ browser = "WinW" | // WinWAP browser $ browser = "UPG1" | // UP. SDK 4.0 $ browser = "upsi" | // another kind of UP. browser ?? $ Browser = "QWAP" | // unknown QWAPPER browser $ browser = "Jigs" | // unknown JigSaw browser $ browser = "Java" | // unknown java based browser $ browser = "Alca" | // unknown Alcatel-BE3 browser (UP based ?) $ Browser = "MITS" | // unknown Mitsubishi browser $ browser = "MOT-" | // unknown browser (UP based ?) $ Browser = "My S" | // unknown Ericsson devkit browser? $ Browser = "WAPJ" | // Virtual WAPJAG www.wapjag.de $ browser = "fetc" | // fetchpage. cgi Perl script from www.wapcab.de $ browser = "ALAV" | // yet another unknown UP based browser? $ Browser = "Wapa" | // another unknown browser (Web based "Wapalyzer "?) $ Browser = "Courier") // Opera {$ br = "WML" ;}else {$ br = "HTML ";}} if ($ br = "WML") {return TRUE;} else {return FALSE ;}} if (! Check_wap () {Header ("Location: http: // youUrl"); exit ();}
Of course, our goal is to return friendly interfaces suitable for non-computer users.

So I think a good way is to use PHP to determine the detailed information of the web browser accessed, the browser size, version, kernel, and so on, to return the web interface in accordance with their aptitude.


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.