==================
Class clientinf.cls:
==================
<?php
class ClientInfo {
/*this class requires an open MySQL connection to a database*/
/*************************************************************************************/
/*this function returns a country name corresponding to code*/
cfunction getctrybycode($code) {
$code=strtolower($code);
$qry="SELECT country FROM ianacode WHERE code='$code'";
$row=mysql_fetch_row(mysql_query($qry));
if($row[0]=='') return($code);
return($row[0]);
}
/*************************************************************************************/
/*this function returns a country name corresponding to a hostname*/
cfunction getctrybyhost($hostname) {
/*************************************************************************************/
/*this function returns a country code name corresponding to a hostname*/
cfunction getctrycodebyhost($hostname) {
return(substr(strrchr($hostname,'.'),1));
}
/*************************************************************************************/
/*this function mask an IP address different from current client using '#'
it returns an unaltered IP if same than client*/
cfunction MaskOtherIP($IP) {
===============
Table ianacode:
===============
See Attached File ianacode.sql
===================
Usage by an example
===================
<?php
require("$ROOTURL/lib/cls/clientinf.cls");
$myCliInf = new ClientInfo;
{ connect your dabase here }
/*Say $IP is the IP of current visitor*/
$IP=getenv("REMOTE_ADDR");
/*try to get hostname */
$hostname=gethostbyaddr($IP);
if(!strcmp($hostname,$addr))
$hostname='(unknown)';
/*get country if known in table ianacode*/
$country=$myCliInf->getctrybyhost($hostname);
print "IP $IP is registered in country=$country.\n";
/*Note:
If0 you chose to display the access log to your visitors,
you may just want to show the numeric IP to the current visitor,
and hide other IP, but not the country names,
then you will do:*/
print "IP ".$myCliInf->MaskOtherIP($IP)." is registered in country=$country.\n";