-
- var Browser_Agent=navigator.userAgent;
- //When the browser is ie
- if(Browser_Agent.indexOf("MSIE") !=-1){
- var a=navigator.browserLanguage;
- if(a !="zh-cn"){
- location.href="English website";
- }
- }
- //The browser is not ie
- else{
- var b=navigator.language;
- if(b!="zh-CN"){
- location.href="English website";
- }
- }
Copy code
Option 2: Use the IP library to determine the visiting IP address
Advantages: Accurate judgment.
Disadvantages: The response speed is not as fast as Javascript.
You need to reference a PHP IP library: /Files/tianxin2001x/ip.zip
Quote jquery at the head of the website for judgment:
-
-
- 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() {
}
- });
- }
-
- ...
-
Copy the code
checkip.php file code:
-
-
$userip=$_SERVER['REMOTE_ADDR'];
- //Reference the files of the ip library and put 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;
- }
-
Copy code
Both of the above two methods can be used to determine the visiting IP address, choose one and use it.
|