Have an account? Sign in
Login  Register  Facebook
ip block country
how can i determine the visitor country e.g us
becuase i want make each us visitor get his country language
Started: September 15, 2011 Latest Activity: September 15, 2011 ip block country
1 Answer
ok its very easy, just you can depend on an api like this
http://api.hostip.info/country.php

see the example:

$country = file_get_contents(\'http://api.hostip.info/country.php\');
echo $country;

This however will return your server location, since the IP would be set as your server IP. So you\'ll have to get the visitors IP via the $_SERVER[\"REMOTE_ADDR\"] which is available in PHP as a \"predefined variable\". Then append their IP to the country endpoint of their API.

Example PHP:

$api = \'http://api.hostip.info/country.php?ip=\';
$country = file_get_contents($api.$_SERVER[\'REMOTE_ADDR\'];
echo $country;

Posted: MacOS
In: September 15, 2011

Ok super PHP code
September 15, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer