Location: PHPKode > projects > CNStats > cnstats/geo/cngeoip5/example.php
<?

if ( !@$_REQUEST['ips'] ) {
    $_REQUEST['ips'] = $_SERVER['REMOTE_ADDR'];
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/plain; charset=utf-8">
<title>CNGeoIP5: example</title>
</head>
<body>

<p>Please, put one IP address per line in this textarea:</p>
<form method=get action=<?=$_SERVER['SCRIPT_NAME']?>>
<textarea cols=25 rows=5 name=ips><?=@$_REQUEST['ips']?></textarea>
<br>
<input type=submit value="Test this IP addresses">
</form>

<?

function __autoload($class) {
    require "$class.php";
}

$cngeo5 = new CNGeoIP();

if ( !$cngeo5->is_valid() ) {
    print "Can't load cngeoip.<br>\n";
    die();
}

$iparr = explode("\n", @$_REQUEST['ips']);


if ( !sizeof($iparr) ) {
    $iparr = array($_SERVER['REMOTE_ADDR']);
}

print "<table width=100% border=1 cellpadding=5 cellspacing=5>\n";

foreach ( $iparr as $ip ) {
    $ip = trim($ip);
    if ( !ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $ip) )
	continue;

    $place = $cngeo5->get_place_by_ip($ip);
    $descr = $cngeo5->get_description_by_ip($ip);
    print "<tr><th>$ip<br>$place</th>\n";
    
    if ( $descr['special'] ) {
	print "<td>$descr[special]</td>\n";
    }
    else {
	foreach ( $descr as $part ) {
	    print "<td valign=top style='font-face: fixed; font-size: 8pt;'>\n";
	    while ( list($k,$v) = each($part) ) {
		print "$k => $v<br>\n";
	    }
	    print "</td>\n";
	}
    }
}


print "</table>\n";

?>

</body>
</html>
Return current item: CNStats