<?php
/*
* test_netgeo.php
*
* @(#) $Header: /home/mlemos/cvsroot/netgeo/test_netgeo.php,v 1.4 2003/12/12 16:36:22 mlemos Exp $
*
*/
?><HTML>
<HEAD>
<TITLE>Test for Manuel Lemos's PHP NetGeo class</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Test for Manuel Lemos's PHP NetGeo class</H1></CENTER>
<HR>
<?php
require("netgeo.php");
$netgeo=new netgeo_class;
$ip=GetEnv("REMOTE_ADDR");
if($netgeo->GetAddressLocation($ip,$location))
{
$longitude=doubleval($location["LONG"]);
$latitude=doubleval($location["LAT"]);
echo "<CENTER><H2>Your approximate location:</H2></CENTER>\n";
echo "<CENTER><TABLE BORDER>\n<TR>\n";
if(IsSet($location["CITY"])
|| IsSet($location["STATE"])
|| IsSet($location["COUNTRY"]))
{
echo "<TD>\n<TABLE>";
if(IsSet($location["CITY"]))
echo "<TR>\n<TH ALIGN=\"right\">City:</TH>\n<TD>".HtmlEntities(ucwords(strtolower($location["CITY"])))."</TD>\n</TR>\n";
if(IsSet($location["STATE"]))
echo "<TR>\n<TH ALIGN=\"right\">State:</TH>\n<TD>".HtmlEntities(ucwords(strtolower($location["STATE"])))."</TD>\n</TR>\n";
if(IsSet($location["COUNTRY"]))
echo "<TR>\n<TH ALIGN=\"right\">Country:</TH>\n<TD>".HtmlEntities(strtolower($location["COUNTRY"]))."</TD>\n</TR>\n";
echo "</TABLE>\n</TD>\n";
}
echo "<TD>\n<TABLE>\n";
echo "<TR>\n<TH ALIGN=\"right\">Longitude:</TH>\n<TD>".($longitude>=0.0 ? $longitude."° East" : (-$longitude)."° West")."</TD>\n</TR>\n";
echo "<TR>\n<TH ALIGN=\"right\">Latitude:</TH>\n<TD>".($latitude>=0.0 ? $latitude."° North" : (-$latitude)."° South")."</TD>\n</TR>\n";
echo "</TABLE>\n</TD>\n</TR>\n";
echo "</TABLE></CENTER>\n";
$places=array(
"Equator line"=>array($longitude,0.0),
"Greenwich line"=>array(0.0,$latitude),
"North Pole"=>array(0.0,90.0),
"South Pole"=>array(0.0,-90.0),
"PHP Classes site"=>array(-117.14,32.80)
);
echo "<CENTER><H2>Distance to reference places in the world</H2></CENTER>\n";
echo "<CENTER><TABLE BORDER>\n<TR>\n<TH>Place</TH>\n<TH>Longitude</TH>\n<TH>Latitude</TH>\n<TH>Distance</TH>\n</TR>\n";
for(Reset($places),$place=0;$place<count($places);Next($places),$place++)
{
$name=Key($places);
$long=$places[$name][0];
$lat=$places[$name][1];
echo "<TR>\n";
echo "<TH>$name</TH>\n";
echo "<TD ALIGN=\"right\"><TT>".($long>0 ? $long."° East" : ($long<0 ? (-$long)."° West" : "0°"))."</TT></TD>\n";
echo "<TD ALIGN=\"right\"><TT>".($lat>0 ? $lat."° North" : ($lat<0 ? (-$lat)."° South" : "0°"))."</TT></TD>\n";
echo "<TD ALIGN=\"right\"><TT>".intval($netgeo->CalculateDistance($longitude,$latitude,$long,$lat))." Km</TT></TD>\n";
echo "</TR>\n";
}
echo "</TABLE></CENTER>\n";
}
else
{
echo "<CENTER><H2>Sorry, could not determine your network location!</H2></CENTER>\n";
echo "<CENTER><H3>Error: ".$netgeo->error.".</H3></CENTER>\n";
}
?>
<HR>
<ADDRESS><a href="mailto:mlemos-at-acm-dot-org" onclick="location.href='mail'+'to'+':'+'mlemos'+unescape('%40')+'acm.org'; return false">mlemos at acm dot org (Manuel Lemos)</a></ADDRESS>
</BODY>
</HTML>
|