How does php determine whether a user accesses through wap on a mobile phone or directly on a computer?

Source: Internet
Author: User
Tags website server
Now we have a lot of smartphone users, and there are also many friends who visit the website using their mobile phones to access them directly. this is a problem. if it is a pc-based mobile phone, it will definitely be difficult to see that the traffic is still charged, so many companies have implemented wap sites, but how should we determine whether the user is a mobile phone or a pc access network... now we have a lot of smartphone users, and there are also many friends who visit the website using their mobile phones to access them directly. this is a problem. if it is a pc-based mobile phone, it will definitely be difficult to see that the traffic is still charged, so many companies have implemented wap sites, but I have sorted out some methods to determine whether a user accesses a website through a mobile phone or a pc.

A mobile phone query system recently involved this issue. I will discuss how to use php to determine whether a user can access the system through wap or a computer.

First, the most fundamental solution:

The user-agent information is sent along with the mobile phone number information. if you can obtain the mobile phone number, it must be accessed through the mobile phone wap. However, China Mobile has blocked the user-agent information, so the mobile phone number cannot be obtained. You can contact a mobile company to submit the ip address of the wap website server to China Mobile. after adding the ip address to the whitelist, you can obtain the ua Information. Currently, China Unicom can directly obtain the mobile phone number, which is perfect for China Unicom users.

My solution is as follows:

The principle of mobile phone access is that the mobile phone is accessed through the proxy server of the mobile company. Then we can understand that a common computer uses a proxy server. When a mobile phone is accessed through a 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

The http header information of other provinces is similar to this one. The scheme to determine whether a mobile phone can be accessed comes out: obtain the http via information string to check whether the string contains wap characters. If yes, it is accessed through a mobile phone. The result is that no one can forge a mobile phone to access the website, and the judgment is absolutely accurate. Naturally, this protects mobile phone wap simulators that are popular on the internet-fundamentally.

The operation code is also simple:

 

According to the materials I have consulted, this method should be the most accurate and simplest method for judging mobile phone access on the Internet so far.

Iphone smartphone

The iphone version for discuz is basically completed. for convenient access, the iphone access is directly judged on the home page, and then directly redirected


The above code is used to determine that the test results are very good.

A judgment class used by myself, comprehensive

 


Article address:

Reprint at will ^ please include the address of this 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.