Frage

I am trying to make a log of users heading to my website. I want to save their IP addresses, as well as city and country info.

Thanks in Advance.

War es hilfreich?

Lösung

You can get the IP from $_SERVER['REMOTE_ADDR']. To get location you will have to find some service that provides lookup and check the IP you just collected.

You might also consider signing up for Google analytics.

Andere Tipps

Try using MaxMind GeoIP database which I find the best solution that's freely available. It has a set of methods to retrieve the city and the country by IP and to get the ip just use: $_SERVER['REMOTE_ADDR']

I Think you should go for Google analytic, All these data you will get from there. Otherwise for ip address you can use this script

function getIP() {
$ip;
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "UNKNOWN";
return $ip;
}

& for country name

http://geoip.wtanaka.com/cc/$ipaddr

this will return country ISO code.

Do the users input their City and Country? If yes then easily save the data to database.

Or do you want to track these by IP? If this one - download/buy the database of the countries by ip from http://www.ip2country.net/download.html and only put the IP into the database.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top