Jump to content

Website visitor


RON_ron

Recommended Posts

Not reliably, no. You can use the IP to determine which country the ISP is registered in, but that doesn't necessarily mean that the user belong to that country as well.

After all, people go on holidays as well as using proxies, and nothing's to say that the geolocation database of your provider is correct. I've had my IP identified as belonging to the Netherlands, quite a few times, and others no result at all.

 

Best way is to ask the user, and then save the result in the database or a cookie.

Link to comment
https://forums.phpfreaks.com/topic/267819-website-visitor/#findComment-1373987
Share on other sites

  • 1 month later...

As Christian said, not reliably.

 

http://www.maxmind.com/en/geolocation_landing

http://www.geoplugin.net

 

can try this

 

$ip = $_SERVER['REMOTE_ADDR'];

//if running this code locally, to get a result
if($ip == $_SERVER['SERVER_ADDR']){
$ip = $_SERVER['SERVER_NAME'];
}
echo $ip."<br />";
$geolocation = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
$geo_city = trim($geolocation['geoplugin_city']);
$geo_country = $geolocation['geoplugin_countryName'];
$location = $geo_city.",".$geo_country;
echo "Location: ".$location."<br />";

 

What you do with their city,country info would be up to you, save it to a user session or database

Link to comment
https://forums.phpfreaks.com/topic/267819-website-visitor/#findComment-1383396
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.