jump to navigation

retrieve visitor country information with PHP February 26, 2011

Posted 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 .

$ipAddr = $_SERVER["REMOTE_ADDR"];
$country_content = file_get_contents("http://api.hostip.info/get_html.php?ip=".$ipAddr);
echo $country_content;


See it in action ..



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s