/ Published in: PHP
This simple code demonstrates how to change automatically site language, according to the visitor's country. If you implement this script in your site it will open the page in the language of your visitor.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // prepare reload to local version according by first visit // prepare reload to local version according by first visit if(!$location_reload){ $location = visitor_location(); $_SESSION["loc_reload"] = true; exit; $_SESSION["loc_reload"] = true; exit; } } function visitor_location(){ $client = @$_SERVER["HTTP_CLIENT_IP"]; $forward = @$_SERVER["HTTP_X_FORWARDED_FOR"]; $remote = @$_SERVER["REMOTE_ADDR"]; $ip = $client; $ip = $forward; }else{ $ip = $remote; } if($ip_data && $ip_data->geoplugin_countryName != null){ $result["country"] = $ip_data->geoplugin_countryCode; $result["city"] = $ip_data->geoplugin_city; } return $result; } ?>
URL: http://www.apphp.com/index.php?snippet=php-change-language-according-to-visitor-country