PHP-Code:
<?php
@require_once ('lib/functions.lib.php');
//@require_once ('lib/layout.lib.php');
error_reporting(E_ALL);
//head("");
//unzip with PHP 5.2.0 or later (zlib)
function unzip($file) {
$zip = new ZipArchive();
if ($zip->open($file) === TRUE) {
$zip->extractTo('./');
$zip->close();
echo 'Erfolgreich entzippt';
} else {
echo 'Konnte Zip nicht öffnen';
}
}
function getRawHttpHeader($host,$doc) {
$httpheader = "";
$fp = fsockopen ($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno) \n";
} else {
fputs ($fp, "GET $doc HTTP/1.0\r\nHost: " . $host. "\r\n\r\n");
while (!feof($fp)) {
$httpresult = fgets ($fp,1024);
$httpheader = $httpheader.$httpresult;
if (ereg("^\r\n",$httpresult)) break;
}
fclose ($fp);
}
return $httpheader;
}
function getArrayHttpHeader($url) {
$url = ereg_replace("http://","",$url);
$endHostPos = strpos($url,"/");
if (!$endHostPos) $endHostPos = strlen($url);
$host = substr($url,0,$endHostPos);
$doc = substr($url,$endHostPos,strlen($url)-$endHostPos);
if ($doc=="") $doc = "/";
$raw = getRawHttpHeader($host,$doc);
$tmpArray = explode("\n",$raw);
for ($i=0;$i<sizeof($tmpArray); $i++) {
@list($name, $value) = explode(':', $tmpArray[$i], 2);
$array[trim($name)]=trim($value);
}
return $array;
}
$filename = 'ip-to-country.csv.zip';
if (file_exists($filename)) {
$falt = date("Y.m.d", filemtime($filename));
echo $falt.' letztes Update<br>';
}
$array = (getArrayHttpHeader("http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip"));
// print_r($array);
// Display last updated timestamp
$fneu = date("Y.m.d",strtotime($array['Last-Modified']));
echo $fneu.' neueste Update<br>';
if ($fneu > $falt) {
//Kopiere und entpacke neues update
if (copy("http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip","ip-to-country.csv.zip")) {
unzip("ip-to-country.csv.zip");
echo '<br>hier cron<br>';
db_connect ();
$delete = db_query("TRUNCATE TABLE laendercode");
$returned='';
$fp=@fopen($_SERVER['DOCUMENT_ROOT'].'/ip-to-country.csv',"r");
if($fp){
while($line=fgets($fp,1000)){
$line = str_replace("\"","",$line);
$werte_array=split(",",$line);
$anfuegen = db_query("INSERT INTO laendercode (IP_FROM, IP_TO, CC2, CC3, land) values ('$werte_array[0]','$werte_array[1]','$werte_array[2]','$werte_array[3]','$werte_array[4]')");
//echo "$werte_array[0],$werte_array[1],$werte_array[2],$werte_array[3],$werte_array[4] <br>";
}
fclose($fp);
}
$test = mysql_fetch_array(db_query("SELECT COUNT(*) as summe FROM laendercode"));
echo $test['summe'].'DB-Einträge<br>';
// Zeit setzen
db_query ("UPDATE ".$db_prefix."_crons SET laufzeit = '".time()."' WHERE bezeichnung = 'Laendercode-DateiUpdate'");
db_close();
}
} else {
echo 'Update war nicht erforderlich.<br>';
}
echo 'here is the end';
//foot();
?>
Bin für Verbesserunge natrlich offen.