Home : General : Perl Programming :

General: Perl Programming: Re: [cK] convert IP to Country: Edit Log

Here is the list of edits for this post
Re: [cK] convert IP to Country
This is what I got working in PHP.. Comments are very welcome! (This is my first php/sql script)

Now I need to get this working in perl...

Code:

<?php

$server="localhost";
$user="xxx";
$pass="xxx";
$db="xxx";

$ip = $_SERVER['REMOTE_ADDR'];

mysql_connect($server, $user, $pass) or die("Unable to connect to SQL server.");
mysql_select_db($db) or die ("Unable to connect to SQL server.");

$sql="SELECT country FROM ip2nation WHERE ip < INET_ATON('$ip') ORDER BY ip DESC LIMIT 0,1";
$result = mysql_query($sql) or die ("Invalid query: " . mysql_error());

while ($row = mysql_fetch_object($result)) {
$countrycode = $row->country;
}

echo "Your IP Address is $ip<br>You're located in '$countrycode'";
mysql_free_result($result);

?>

Last edited by:

cK: Apr 25, 2003, 8:22 AM

Edit Log: