retrieve visitor country information

I am quite busy for the pass 1-2 months and did not update this blog.
Today I would like to share a simple and useful script to all on how to retrieve visitor 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.

Example:

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

Sample Result:

Country: SINGAPORE (SG)
City: Singapore
IP: XXX.XXX.XXX.XXX

One Comment to “retrieve visitor country information”

  1. Misti Savas 24 August 2011 at 1:19 pm #

    What’s Going down i am new to this, I stumbled upon this I’ve discovered It absolutely helpful and it has helped me out loads. I am hoping to contribute & aid different users like its aided me. Good job.


Leave a Reply