1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

display users nearest city

Discussion in 'PHP & Perl' started by bk4life, Dec 26, 2009.

  1. bk4life

    bk4life Newbie

    Joined:
    Jan 10, 2008
    Messages:
    43
    Likes Received:
    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
     
  2. bu11d0g

    bu11d0g Guest

    Could try this:
    Code:
    http://www.danasoft.com/
     
  3. bk4life

    bk4life Newbie

    Joined:
    Jan 10, 2008
    Messages:
    43
    Likes Received:
    1
    Kinda looking for just it spitting out the city in plain text. thanks though :)
     
  4. ukescuba

    ukescuba Senior Member

    Joined:
    Feb 24, 2008
    Messages:
    994
    Likes Received:
    635
    Occupation:
    Mobile Marketer & QR Code Junkie
    Location:
    San Antonio, TX
    Home Page:
    search on here for maxmind.com or look directly at this page:

    Code:
    http://www.maxmind.com/app/ip-location
     
  5. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,232
    Occupation:
    Retired
    Location:
    Old Peoples Home
    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 Thanks x 3
  6. brainpower

    brainpower Junior Member

    Joined:
    Mar 23, 2009
    Messages:
    146
    Likes Received:
    26
    fatboy sweeet thx
     
  7. bk4life

    bk4life Newbie

    Joined:
    Jan 10, 2008
    Messages:
    43
    Likes Received:
    1
    thanks dude!
     
  8. phr34k

    phr34k Newbie

    Joined:
    Feb 17, 2009
    Messages:
    9
    Likes Received:
    1
    Occupation:
    CEO of a web development agency
    Location:
    Memphis, TN USA
    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