Tag: Country code

  • Get the visitor’s country by their IP

    Basically the code is something like this:   function check_contry(){ $ip = $_SERVER[“REMOTE_ADDR”]; if (filter_var(@$_SERVER[‘HTTP_X_FORWARDED_FOR’], FILTER_VALIDATE_IP))} $ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’]; } if (filter_var(@$_SERVER[‘HTTP_CLIENT_IP’], FILTER_VALIDATE_IP)){ $ip = $_SERVER[‘HTTP_CLIENT_IP’]; } $ipdata = @json_decode(file_get_contents(“http://www.geoplugin.net/json.gp?ip=” . $ip)); return $ipdata->geoplugin_countryCode; } So we are using the GeoPlugin API to retrieve the Country code. You can also get the full country name,…