display users nearest city

bk4life

Newbie
Joined
Jan 10, 2008
Messages
43
Reaction score
1
hi,

i was wondering if anyone had a script that whenever a user would visit your site, it would simply display in plain text their city, or the nearest city near them.

thanks,

brian
 
Kinda looking for just it spitting out the city in plain text. thanks though :)
 
search on here for maxmind.com or look directly at this page:

Code:
http://www.maxmind.com/app/ip-location
 
Code:
<?php
	if ($_SERVER["HTTP_X_FORWARDED"]) 
	{
		$ip = $_SERVER["HTTP_X_FORWARDED"];
	} 
	elseif ($_SERVER["HTTP_FORWARDED_FOR"]) 
	{
		$ip = $_SERVER["HTTP_FORWARDED_FOR"];
	} 
	elseif ($_SERVER["HTTP_FORWARDED"]) 
	{
		$ip = $_SERVER["HTTP_FORWARDED"];
	} 
	elseif ($_SERVER["HTTP_X_FORWARDED"]) 
	{
		$ip = $_SERVER["HTTP_X_FORWARDED"];
	} 
		else 
	{
		$ip = $_SERVER["REMOTE_ADDR"];
	}
						
	$geo = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
	$city = $geo['geoplugin_city'];

        echo $city;
?>

Theres a starter for you - free for Christmas ;)
 
Code:
<?php
	if ($_SERVER["HTTP_X_FORWARDED"]) 
	{
		$ip = $_SERVER["HTTP_X_FORWARDED"];
	} 
	elseif ($_SERVER["HTTP_FORWARDED_FOR"]) 
	{
		$ip = $_SERVER["HTTP_FORWARDED_FOR"];
	} 
	elseif ($_SERVER["HTTP_FORWARDED"]) 
	{
		$ip = $_SERVER["HTTP_FORWARDED"];
	} 
	elseif ($_SERVER["HTTP_X_FORWARDED"]) 
	{
		$ip = $_SERVER["HTTP_X_FORWARDED"];
	} 
		else 
	{
		$ip = $_SERVER["REMOTE_ADDR"];
	}
						
	$geo = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
	$city = $geo['geoplugin_city'];

        echo $city;
?>

Theres a starter for you - free for Christmas ;)

thanks dude!
 
I've been using Micah Carrick's php class to handle this for a couple of years now. I am not sure how up to date the database is, but it's always worked fine for me. It's free and easy to setup/use..

hxxp://www.micahcarrick.com/04-19-2005/php-zip-code-range-and-distance-calculation.html
 
Back
Top