Ip Location

Discussion in 'PHP' started by Kakish, Jul 1, 2009.

  1. #1
    Greetings,

    I need code to find out the visitors country in php.. i also need a flag for that country and a google map of his/her location...

    Thanks
     
    Kakish, Jul 1, 2009 IP
  2. AlilG

    AlilG Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
    	
    	$server   = ''; // MySQL hostname
    	$username = ''; // MySQL username
    	$password = ''; // MySQL password
    	$dbname   = ''; // MySQL db name
    	
    	
    	$db = mysql_connect($server, $username, $password) or die(mysql_error());
    	      mysql_select_db($dbname) or die(mysql_error());
    	
    	$sql = 'SELECT 
    	            c.country 
    	        FROM 
    	            ip2nationCountries c,
    	            ip2nation i 
    	        WHERE 
    	            i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") 
    	            AND 
    	            c.code = i.country 
    	        ORDER BY 
    	            i.ip DESC 
    	        LIMIT 0,1';
    	
    	list($countryName) = mysql_fetch_row(mysql_query($sql));
    	
    	// Output full country name
    	echo $countryName;
    	
    ?>
    
    PHP:
    and download the latest ip 2 nation database from this url
    
    http://www.ip2nation.com
    
    Code (markup):
     
    AlilG, Jul 1, 2009 IP
  3. vaibhavcoder

    vaibhavcoder Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I was about to give the solution but your code is much simpler then mine ,great thank you for your help.

    Noddy
     
    vaibhavcoder, Jul 1, 2009 IP
  4. AlilG

    AlilG Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i picked it up from this url
    
    http://www.ip2nation.com/ip2nation/Sample_Scripts
    
    Code (markup):
    it also provide samples for Google Map API
    
    http://www.ip2nation.com/ip2nation/Sample_Scripts/Google_Maps_API
    
    Code (markup):
     
    AlilG, Jul 1, 2009 IP
  5. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Thank you allig. Your code worked correctly. Do you have any collection of SQL database of all the cities/states in the world country wise ?
     
    techbongo, Jul 1, 2009 IP
  6. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
  7. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #7
    i use geo-ip for this works like a charm
     
    Bohra, Jul 1, 2009 IP
  8. ahmbay

    ahmbay Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ahmbay, Jul 1, 2009 IP