Total Pageviews

Wednesday, May 29, 2013

Location based Auto currency Updater in PHP, Currency and Update with two different sites..




$exectime = microtime();
$exectime = explode(" ",$exectime);
$exectime = $exectime[1] + $exectime[0];
$starttime = $exectime;

function get_geo_ip_code_wtanka($ipaddr)
{
set_time_limit(3); /// time in second 3 sec if it will take more then means  next function will be load..
$userip = file_get_contents("http://geoip.wtanaka.com/cc/".$_SERVER['REMOTE_ADDR']);
$userip  = strtolower($userip);
return $userip;
}
//echo $userip;

function get_geo_ip_code_sourceforge($ipaddr)
{
$userip = file_get_contents("http://ip2country.sourceforge.net/ip2c.php?format=JSON&ip=$ipaddr");
$userip = str_replace('"','',$userip);
$userip = '"'.$userip.'"';   /* it will returns u the JSON formate however u want u can change*/
$otup = json_decode($userip);
$otup = str_replace('{','',$otup);
$otup = str_replace('}','',$otup);
$otup  = explode(',',$otup);
$len = count($otup);
$new = array();
for($i=1;$i<$len;$i++)
{
$rite = explode(':',$otup[$i]);
$new[] = array($rite[0]=>$rite[1]);
}
$value = strtolower($new[1]['country_code']);
$value = $value;
return $value;
 
}


$userip = get_geo_ip_code_wtanka($_SERVER['REMOTE_ADDR']) ;


$exectime = microtime();
$exectime = explode(" ",$exectime);
$exectime = $exectime[1] + $exectime[0];
$endtime = $exectime;
$totaltime = ($endtime - $starttime);
$ipaddr =$_SERVER['REMOTE_ADDR'];
if($totaltime>=3 || !file_exists("http://geoip.wtanaka.com/cc/$ipaddr") )
$userip = get_geo_ip_code_sourceforge($_SERVER['REMOTE_ADDR']);




Follow kvn_krishna on Twitter