First of all, your site itself has multiple language versions. Otherwise you can only use JS to transform.
1. Through the IP to locate, this to refer to the third-party interface for the full return of data, but do not know whether my network is too slow or what the reason, personally think this method will Kaka:
get the IP of the visitor
functionGetIP () {if(isset($_server)) { if(isset($_server[' Http_x_forwarded_for '])) { $realip=$_server[' Http_x_forwarded_for ']; } ElseIf(isset($_server[' Http_client_ip '])) { $realip=$_server[' Http_client_ip ']; } Else { $realip=$_server[' REMOTE_ADDR ']; } } Else { if(getenv("Http_x_forwarded_for")) { $realip=getenv("Http_x_forwarded_for"); } ElseIf(getenv("Http_client_ip")) { $realip=getenv("Http_client_ip"); } Else { $realip=getenv("REMOTE_ADDR"); } } return $realip;}$ip=GetIP ();
Through the acquisition of IP and third-party interface to achieve docking, the return is the JSON format of data, conversion format, you can get a complete array, the following is taken country the value of this key to judge, can be country_id. Header to the URL of the language version you want to jump to. $res 0=file_get_contents("Http://ip.taobao.com/service/getIpInfo.php?ip= $ip");$res 0= Json_decode ($res 0,true);//echo $res 0[' data ' [' Country '];exit;if($res 0[' Data '] [' country '] = = ' America ' | |$res 0[' Data '] [' country '] = = ' UK ') { Header("location:/en");}Else if($res 0[' Data '] [' country '] = = ' Germany ') { Header("LOCATION:/DW");}Else{ Header("location:/");}
2. Determine which language to display by retrieving the meta-browser. This can be either with JS or with PHP can be achieved. I'm using PHP.
use PHP's $_server[' http_accept_language ' This function to get the meta value of the Web site currently open by the browser, and then cut the string to compare, then header to the specified website.
$langestrtolower(substr($_server[' http_accept_language '], 0, 2)); if ($lange= = ' en ') {header("location:/en");} Else if ($lange = = ' de ') {header("LOCATION:/DW");}
PHP implementation displays different language versions of websites in different countries