I have come up with two solutions:
1. Javascript judges the visitor's browser language. If it is a Chinese system, all natural users are Chinese and skip Chinese websites;
If it is not a Chinese system, the default user is not Chinese and the English-speaking website is skipped.
Advantage: quick response.
Disadvantage: inaccurate. It is possible that Chinese users prefer the English version of the system or that foreigners use the Chinese version of the system.
Code
Copy codeThe Code is as follows:
<Script type = "text/javascript" language = "javascript">
Var Browser_Agent = navigator. userAgent;
// When the browser is ie
If (Browser_Agent.indexOf ("MSIE ")! =-1 ){
Var a = navigator. browserLanguage;
If (! = "Zh-cn "){
Location. href = "English website ";
}
}
// Non-ie browser
Else {
Var B = navigator. language;
If (B! = "Zh-CN "){
Location. href = "English website ";
}
}
</Script>
2. Use the IP address library to determine the access IP Address
Advantage: accurate judgment.
Disadvantage: the response speed is not Javascript fast.
You need to reference a php ip library ip_php.zip
I reference jquery in the website header for judgment.
Copy codeThe Code is as follows:
<Script type = "text/javascript" src = "/javascript/jquery-1.3.2.min.js"> </script>
<Script type = "text/javascript" language = "javascript">
Function initurl (){
$. Ajax ({
Type: "GET ",
Url: "checkip. php ",
DataType: "html ",
Data: "& time =" + new Date (),
Cache: false,
Async: false,
BeforeSend: function (XMLHttpRequest ){
},
Success: function (msg ){
// If the return value is 1, the visitor is the ip address of the China region.
If (msg = 1 ){
// Alert ('I am China ip ');
}
Else {
// Alert ('I am not China ');
Location. href = "English website ";
}
},
Complete: function (XMLHttpRequest, textStatus ){
},
Error: function (){
}
});
}
</Script>
<Body onload = "initurl ()">
...
</Body>
Code for the checkip. php page:
Copy codeThe Code is as follows:
$ Userip = $ _ SERVER ['remote _ ADDR '];
// Reference the ip library file to put all the files in ip.zip under the lib directory
Include_once ('/lib/iplimit. class. php ');
$ Iplimit = new iplimit;
If ($ iplimit-> setup ($ userip ))
{
Echo 1;
}
Else
{
Echo 2;
}
Both methods can be used to determine the access IP address perfectly.