retrieve visitor country information with PHP February 26, 2011Posted by Tournas Dimitrios in PHP.
Today I would like to share a simple and useful script , on how to retrieve visitor’s country information.
It is useful when you want to analysis/track your visitor information (similar with those webstats that show the visitors country information) .I am using the api service from the hostip.info.
By passing the visitor IP Address to api service, it will return the country information to your script .Of course you can parse the output to get only a specific portion of the returned information .
With a little imagination this script could be combined with Flash/Flex applications . By default the Flash Player allows your site to retrieve data from your domain only (security reasons) . Creating a small proxy-server with PHP these restrictions could be by passed .
<?php $ipAddr = $_SERVER["REMOTE_ADDR"]; $country_content = file_get_contents("http://api.hostip.info/get_html.php?ip=".$ipAddr); echo $country_content; ?>