Online now there are three views, one is based on the browser sent User-agent, but obviously this method is not feasible, although some people list the most mobile phone sent user-agent, but there will still be a lot of mobile phones are not recognized, and even some mobile browsers do not send User-agent, And there is no guarantee that a new brand will be in the future.
Here's an example of PHP, and you'll see 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 is to judge Http_accept, this should be relatively reliable, but http_accept is very complex, if the general HTML browser is good to say, you just have to judge the browser support WML and do not support HTML, But if the browser supports WML and HTML at the same time, the low-end phone may put WML in front of the HTML, but many high-end phones or smartphones have good HTML support, so HTML will appear in front of WML.
This is the http_accept sent by the BlackBerry phone.
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, huh? But it is very standard, developers can get a lot of information based on this, but many phones are not so standard, if you look at IE or FF http_accept you will find it very short.
Text/html,
Application/xhtml+xml,
application/xml;q=0.9,
*/*;q=0.8
Also, 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 ');
Rationale: If the browser supports WML and [does not support HTML] or [WML takes precedence over HTML], it is judged to be a phone. But in fact this principle is not correct.
There is a way to judge the gateway or IP or something, but I personally think this is very unreliable, the mobile phone is a lot of networking, such as when I developed a simulator. This should not be an example, REMOTE_ADDR is enough.
The above is my work this morning, but actually still did not find the perfect solution, first write so much, there is a problem please add or send a message to me, if you have a better way to hope to share to me, thank you.
Recently made a mobile phone query system, naturally involved in this problem, then I will be based on the understanding of the WAP through PHP to determine the user access is through the WAP access or direct computer access.
First of all, the most fundamental solution:
Mobile phone access, will be accompanied by sending user-agent information, this information will have a mobile phone number information, then if you can get a mobile phone number, you can certainly be accessed by WAP mobile phone. But China Mobile has blocked the user-agent information so far, so it can't get the phone number. Friends can contact the mobile company, the WAP website server IP submitted to China Mobile, join the white list can obtain UA information. At present, China Unicom can directly take the mobile phone number, to the Unicom users of this program can be implemented perfectly.
Next say my solution:
Mobile phone access, the principle is the mobile phone through the mobile company's proxy server for access. Then we can understand that a common computer uses a proxy server. When the 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 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
Other provinces of the HTTP header information and this is similar, to determine whether the mobile phone access scheme is out: Get the HTTP via information string to see if it contains WAP characters, if any, is accessed through the mobile phone. The result of this is that no one can forge a mobile phone visit and judge the absolute accuracy. Naturally, so for the online popular mobile phone WAP simulator also made a shield-fundamentally shielded.
The operation code is also simple:
Check if WAP by Xhat
function Check_wap () {
Return Stristr ($_server[' Http_via '), "WAP")? True:false;
}
Check over
Judging from the data I have consulted, this method should be the most accurate and simple way to judge mobile phone access to date on the Internet.
The above method can be used to determine whether the source of access is a mobile phone or a computer, but there is a problem is only through the mobile phone to access, support WAP browser and mobile phone simulator also can not access, this has brought trouble to the test, but also a bit limited to death.
The following scenarios are:
Determine whether a WAP-enabled browser determines the access page by judging the browser proxy identifier. One drawback is that it is not possible to list all of the phone's browser identifiers with the supported browser identifier.
Here's a look at the implementation 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 ();
}
http://www.bkjia.com/PHPjc/747073.html www.bkjia.com true http://www.bkjia.com/PHPjc/747073.html techarticle Online Now there are three views, one is based on the browser sent User-agent, but obviously this method is not feasible, although someone listed most of the mobile phone sent user-agent, but still ...