<?
     function writeCacheBan22($content, $filename) {
  $fp = fopen(ROOT.'/_images/cache/geolocal/' . $filename, 'w');
  fwrite($fp, $content);
  fclose($fp);
}
      
      function readCacheBan22($filename, $expiry) {
  if (file_exists(ROOT.'/_images/cache/geolocal/' . $filename)) {
    if ((time() - $expiry) > filemtime('_images/cache/geolocal/' . $filename))
      return FALSE;
    $cache = file(ROOT.'/_images/cache/geolocal/' . $filename);
    return implode('', $cache);
  }
  return FALSE;
} 
 
  ob_start();
$name22 = md5($ank['id'].'geolocal');
if (!$main222_cache = readCacheBan22($name22.'.geolocal.cache', 600)){
//Кэширование

$ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . long2ip($ank['ip'])));

//get country full name
if(property_exists($ipdat, 'geoplugin_countryName')) {
    echo "<span class=\"ank_n\">Страна: </span>";
    echo '<span class="ank_d">'.$ipdat->geoplugin_countryName.'</span><br />';
}
if(property_exists($ipdat, 'geoplugin_countryCode')){
    echo "<span class=\"ank_n\">Код страны: </span>";
    echo '<span class="ank_d">'.$ipdat->geoplugin_countryCode.'</span><br />';
}else{
     echo "<span class=\"ank_n\">Регион: </span>";
    echo '<span class="ank_d">Не определился</span><br />';
}
$main222_cache = ob_get_contents();
    ob_clean();
$name22 = md5($ank['id'].'geolocal');
    writeCacheBan22($main222_cache,$name22.'.geolocal.cache');
} 

ob_end_clean();
echo $main222_cache; 

/*end banbase.ru*/