No comments
<?
$a=array();
// get real ip adress
@detectProxy($a);
$ip_avant = $a['IP'];
//get localisation
$ip2country = @ip2country($ip_avant);
print_r($ip2country );
function ip2country($ipadress)
{
$surl = "http://whatismyipaddress.com/staticpages/index.php/lookup-results";
$data = "LOOKUPADDRESS=" . $ipadress;
$geolocalisation = do_post_request($surl, $data);
preg_match("#<font class='block-title'>Geo-Location Information<font size=2></B></font></font><P><UL>(.*?)</TABLE>#is", $geolocalisation, $mylocalistion, PREG_OFFSET_CAPTURE);
preg_match("#<TR><TD>Country</TD><TD>(.*?)<#is", $mylocalistion[1][0], $country, PREG_OFFSET_CAPTURE);
preg_match("#<img src=\"(.*?)\"#is", $mylocalistion[1][0], $countryimg, PREG_OFFSET_CAPTURE);
preg_match("#<TR><TD>City</TD><TD>(.*?)</TD>#is", $mylocalistion[1][0], $city, PREG_OFFSET_CAPTURE);
$a = array ("country" => trim($country[1][0]), "city" => trim($city[1][0]), "countryimg" => trim($countryimg[1][0]));
return $a;
}
function do_post_request($url, $data, $optional_headers = null) {
$start = strpos($url,'//')+2;
$end = strpos($url,'/',$start);
$host = substr($url, $start, $end-$start);
$domain = substr($url,$end);
$fp = pfsockopen($host, 80);
if(!$fp) return null;
fputs ($fp,"POST $domain HTTP/1.1\n");
fputs ($fp,"Host: $host\n");
if ($optional_headers) {
fputs($fp, $optional_headers);
}
fputs ($fp,"Content-type: application/x-www-form-urlencoded\n");
fputs ($fp,"Content-length: ".strlen($data)."\n\n");
fputs ($fp,"$data\n\n");
$response = "";
while(!feof($fp)) {
$response .= fgets($fp, 1024);
}
fclose ($fp);
return $response;
}
function detectProxy(&$ar)
{//begin of function
$gotcha=false;
if(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER) || array_key_exists('HTTP_PROXY_CONNECTION',$_SERVER) || array_key_exists('HTTP_VIA',$_SERVER))
{$gotcha=TRUE;}
$gotcha = (stristr($_SERVER['REMOTE_HOST'],"proxy") !== FALSE ) ? TRUE : $gotcha ;
if($gotcha)
{
$ar['PORT']= (array_key_exists('REMOTE_PORT',$_SERVER) ? $_SERVER['REMOTE_PORT'] : "unknown");
$ar['HOST']= (array_key_exists('REMOTE_HOST',$_SERVER) ? $_SERVER['REMOTE_HOST'] : "unknown");
$ar['IP']= (array_key_exists('REMOTE_ADDR',$_SERVER) ? $_SERVER['REMOTE_ADDR'] : "unknown");
$ar['FORWARDED_FOR']=(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : "unknown");
$ar['INFO']= (array_key_exists('HTTP_VIA',$_SERVER) ? $_SERVER['HTTP_VIA'] : "unknown");
}
else
{
$ar['PORT']= (array_key_exists('REMOTE_PORT',$_SERVER) ? $_SERVER['REMOTE_PORT'] : "unknown");
$ar['HOST']= (array_key_exists('REMOTE_HOST',$_SERVER) ? $_SERVER['REMOTE_HOST'] : "unknown");
$ar['IP' ]= (array_key_exists('REMOTE_ADDR',$_SERVER) ? $_SERVER['REMOTE_ADDR'] : "unknown");
}
return $gotcha;
}//end of function
?>