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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.