I roughly thought about it, and there are two options:
1. Javascript determines the browser language of the visitor. If it is a Chinese system, naturally the users are Chinese and jump to the Chinese website;
If it is not Chinese system, default users are non-Chinese and jump to English websites.
Advantages: Fast judgment and reflection.
Disadvantages: Inaccurate. It is possible that Chinese users prefer to use the English version of the system, or foreigners use the Chinese system.
Code
Copy code The code is as follows:
2. Use the IP library to judge the visiting IP
Advantages: Accurate judgment.
Disadvantages: The response speed is not as fast as Javascript.
Need to reference a PHP IP library ip_php.zip
I quoted jquery at the head of the website for judgment
Copy code The code is as follows:
< ;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, it means the visitor is an IP in China
if(msg == 1){
//alert ('I am China ip');
}
else {
//alert('I am not China ip');
location.href="English website";
}
},
complete:function(XMLHttpRequest,textStatus) {
},
error:function() {
}
});
}
< /script>
...
Code of checkip.php page:
Copy code The code is as follows:
$userip=$_SERVER['REMOTE_ADDR'];
//Reference the ip library The file puts all the files in ip.zip in the lib directory
include_once('/lib/iplimit.class.php');
$iplimit = new iplimit;
if($iplimit-> setup($userip))
{
echo 1;
}
else
{
echo 2;
}
Both methods can perfectly determine the visiting IP. Which one you choose depends on your specific needs.
http://www.bkjia.com/PHPjc/320904.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320904.htmlTechArticleI roughly thought about it and there are two options: 1. Javascript determines the browser language of the visitor. If it is Chinese system, naturally all users are Chinese, jump to Chinese websites; if it is not...