Web Hosting Info

Search:

featured partner

The IP to Country Database

  Forum Topics : Support / Display visitors Ip and country on a php page
Submitted by gutguy on Mon, 12/05/2005 - 12:45.
hi,
i've read around but i still can't find the code to do this.
I'd like to display visitor's ip address and country on a php page on my website, how can I do this?
Thanks.
Comment viewing options:
Select your preferred way to display the comments and click 'Save settings' to submit your changes.
Some code can be found there
Posted by D_A on Tue, 12/06/2005 - 12:20.
Some code can be found there :
http://d1.a.free.fr/en/how_to.php#ip2country
then add
echo "IP: $no_ip Country: $paysdorigine";
 
I made a similar code with co
Posted by Eben on Sat, 05/20/2006 - 11:37.
I made a similar code with country flags just go to Development forum or just visit http://www.eyalb.tk

The code to display each visitor's ip and country name is:
--------------------------------------------------------------
///////////////////////////////////////////////////////////
// IP-To-Country Users Online v1.1
////////////////////////////////////////////////////////
// Created by Eyal Benatav
// Site: http://www.eyalb.tk
// E-Mail: eyalb81@gmail.com
// License: FREE
////////////////////////////////////////////////////

//Data base settings
$server = "localhost";
$db_user = "user";
$db_pass = "pass";
$database = "db";
$dbh = mysql_connect($server, $db_user, $db_pass);

while ($row = mysql_fetch_array($result)) {
$country_query = '
SELECT country_name
FROM iptocountry
WHERE ipfrom < INET_ATON("'.$row['ip'].'")
ORDER BY ipfrom DESC
LIMIT 0,1';

//set in array
$country_exec = mysql_query($country_query);
$ccode_array=mysql_fetch_array($country_exec);
$country_name=$ccode_array['country_name'];

//echo $row[ip] . '-' . $country_code;
// cut ip to 5 digits
$line = substr("$row[ip]",0,5);
// add
(line) and masking with xx.xx
$showip = chunk_split($line,30,".xx.xx  \n");
// display results
echo "$showip - $country_name\n";
}

mysql_close($dbh);
?>