


How to determine whether the access terminal is a computer or a mobile phone?_PHP tutorial
There are currently three opinions on the Internet. One is based on the User-Agent sent by the browser, but obviously this method does not work. Although some people have listed the User-Agent sent by most mobile phones, but There are still many mobile phones that cannot be recognized, and some mobile browsers even do not send User-Agent, and there is no guarantee that new brands will not be released in the future.
Below is an example of PHP. After reading it, you will know how unreliable it is.
1. function is_wap(){
2. $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
3. $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|sie|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile)/i";
4. if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')){
5. return true;
6. }else{
7. return false;
8. }
9. }
The other method is to judge HTTP_ACCEPT, which should be relatively reliable, but HTTP_ACCEPT is very complicated. If the general browser does not support html, it is easy to say. You only need to judge that the browser supports wml and does not support html. But if the browser supports both wml and html, it will be difficult. Low-end mobile phones may put wml in front of html, but many high-end mobile phones or smart phones have good support for html, so html will also appear in front of wml. .
This is the HTTP_ACCEPT sent by the BlackBerry
Application/vnd.rim.html,
text/html,
Application/vnd.wap.xhtml+xml,
text/vnd.sun.j2me.app-descriptor,
image/vnd.rim.png,image/jpeg,
Application/x-vnd.rim.pme.b,
Application/vnd.rim.ucs,
Image/gif;anim=1,
Application/vnd.rim.jscriptc;v=0-8-8,
Application/x-javascript,
Application/vnd.rim.css;v=1,
text/css;media=handheld,
Application/vnd.wap.wmlc;q=0.9,
Application/vnd.wap.wmlscriptc;q=0.7,
text/vnd.wap.wml;q=0.7,
*/*;q=0.5
Exaggerated? But it is indeed very standard. Developers can get a lot of information based on this, but many mobile phones are not so standard. If you check the HTTP_ACCEPT of IE or FF, you will find that it is very short.
text/html,
Application/xhtml+xml,
Application/xml;q=0.9,
*/*;q=0.8
Similarly, let me give you an example of php.
if (isset($_SERVER['HTTP_ACCEPT']) &&
(strpos($_SERVER['HTTP_ACCEPT'],'vnd.wap.wml')!==FALSE)
&& (strpos($_SERVER['HTTP_ACCEPT'],'text/html')===FALSE ||
(strpos($_SERVER['HTTP_ACCEPT'],'vnd.wap.wml') <
strpos($_SERVER['HTTP_ACCEPT'],'text/html'))
)) {//Mobile access
readfile('index.wml');
} else readfile('index.htm');
Principle: If the browser supports WML and [does not support HTML] or [WML takes precedence over HTML], it is determined to be a mobile phone. But in fact this principle is incorrect.
There is another way to determine the gateway or IP, but I personally think this is very unreliable. There are many ways to connect to mobile phones. For example, when I was developing, I used an emulator. There should be no examples for this, REMOTE_ADDR is Enough.
The above is the result of my work this morning, but in fact I still haven’t found a perfect solution. I’m just writing this much. If you have any questions, please add them or send me a message. If you have a better way, I hope you can share it with me. , thank you.
Recently I was working on a mobile phone query system, which naturally involved this issue. Then I will use PHP to judge whether the user access method is through WAP access or direct computer access based on my understanding of WAP.
Let’s talk about the most fundamental solution first:
When accessing via mobile phone, user-agent information will be sent. This information will contain mobile phone number information. If you can obtain the mobile phone number, you can definitely access it through mobile wap. However, China Mobile has currently blocked user-agent information, so the mobile phone number cannot be obtained. Friends who are related can contact the mobile company and submit the IP of the WAP website server to China Mobile. After adding it to the whitelist, the UA information can be obtained. At present, China Unicom can directly obtain mobile phone numbers, and this solution can be implemented perfectly for Unicom users.
Now let’s talk about my solution:
The principle of mobile phone access is that the mobile phone accesses through the proxy server of the mobile company. Then we can understand that an ordinary computer uses a proxy server. When a mobile phone accesses through a proxy server, the http header information will undoubtedly contain a piece of information: via. 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)
The via information of Henan Unicom is:
zxwap gateway,zte technologies
The http header information in other provinces is similar to this. Here is a solution to determine whether mobile access is possible: Get the via information string of http to see if it contains wap characters. If so, it is accessed via mobile phone. The result of this is that no one can fake mobile phone access and the judgment is absolutely accurate. Naturally, this also blocks the popular mobile phone wap simulators on the Internet - fundamentally blocking them.
The operation code is also very simple:
// check if wap by xhat
Function check_wap() {
return stristr($_SERVER['HTTP_VIA'],"wap") ? true : false;
}
// check over
Judging from the information I have reviewed, this method should be the most accurate and simplest way to determine mobile phone access on the Internet so far.
The above method can determine whether the access source is a mobile phone or a computer, but one problem is that it can only be accessed through a mobile phone, and browsers and mobile phone simulators that support WAP cannot be accessed, which brings trouble to the test. It’s also a bit restrictive.
The following plan is:
Determine the access page by judging the browser proxy identifier and whether it is a browser that supports WAP. One disadvantage of this is that it is impossible to list all the browser identifiers and supported browser identifiers of all mobile phones.
Let’s take a look at the implemented code:
Function check_wap()
{
if (strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0)
{
// Check whether the browser/gateway says it accepts WML.
$br = "WML";
}
else
{
$browser=substr(trim($_SERVER['HTTP_USER_AGENT']),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.Browser
$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=="Oper") // Opera
{
$br = "WML";
}
else
{
$br = "HTML";
}
}
if($br == "WML")
{
return TRUE;
}
else
{
return FALSE;
}
}
if(!check_wap())
{
Header("Location: http://www.xker.com/");
exit();
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PS "Loading" problems are caused by resource access or processing problems: hard disk reading speed is slow or bad: Use CrystalDiskInfo to check the hard disk health and replace the problematic hard disk. Insufficient memory: Upgrade memory to meet PS's needs for high-resolution images and complex layer processing. Graphics card drivers are outdated or corrupted: Update the drivers to optimize communication between the PS and the graphics card. File paths are too long or file names have special characters: use short paths and avoid special characters. PS's own problem: Reinstall or repair the PS installer.

PS card is "Loading"? Solutions include: checking the computer configuration (memory, hard disk, processor), cleaning hard disk fragmentation, updating the graphics card driver, adjusting PS settings, reinstalling PS, and developing good programming habits.

Solving the problem of slow Photoshop startup requires a multi-pronged approach, including: upgrading hardware (memory, solid-state drive, CPU); uninstalling outdated or incompatible plug-ins; cleaning up system garbage and excessive background programs regularly; closing irrelevant programs with caution; avoiding opening a large number of files during startup.

"Loading" stuttering occurs when opening a file on PS. The reasons may include: too large or corrupted file, insufficient memory, slow hard disk speed, graphics card driver problems, PS version or plug-in conflicts. The solutions are: check file size and integrity, increase memory, upgrade hard disk, update graphics card driver, uninstall or disable suspicious plug-ins, and reinstall PS. This problem can be effectively solved by gradually checking and making good use of PS performance settings and developing good file management habits.

The reason for slow PS loading is the combined impact of hardware (CPU, memory, hard disk, graphics card) and software (system, background program). Solutions include: upgrading hardware (especially replacing solid-state drives), optimizing software (cleaning up system garbage, updating drivers, checking PS settings), and processing PS files. Regular computer maintenance can also help improve PS running speed.

The article introduces the operation of MySQL database. First, you need to install a MySQL client, such as MySQLWorkbench or command line client. 1. Use the mysql-uroot-p command to connect to the server and log in with the root account password; 2. Use CREATEDATABASE to create a database, and USE select a database; 3. Use CREATETABLE to create a table, define fields and data types; 4. Use INSERTINTO to insert data, query data, update data by UPDATE, and delete data by DELETE. Only by mastering these steps, learning to deal with common problems and optimizing database performance can you use MySQL efficiently.

MySQL cannot run directly on Android, but it can be implemented indirectly by using the following methods: using the lightweight database SQLite, which is built on the Android system, does not require a separate server, and has a small resource usage, which is very suitable for mobile device applications. Remotely connect to the MySQL server and connect to the MySQL database on the remote server through the network for data reading and writing, but there are disadvantages such as strong network dependencies, security issues and server costs.

MySQL can run without network connections for basic data storage and management. However, network connection is required for interaction with other systems, remote access, or using advanced features such as replication and clustering. Additionally, security measures (such as firewalls), performance optimization (choose the right network connection), and data backup are critical to connecting to the Internet.
