Ich habe mir ein kleines Dereferer Script geschrieben, welches gleich noch kaputte Links mitzählt. Habt ihr Verbesserungsvorschläge? Dürft ihr gern frei weiterverwenden.
Code: Alles auswählen
<?php
$URL = $_REQUEST['link'];
$id = (int)mysql_escape_string($_REQUEST['id']);
$URLInfo = parse_url($URL);
$DocumentPath = ($URLInfo["path"])?$URLInfo["path"]:"/";
if ($URLInfo["query"]) $DocumentPath = $DocumentPath."?".$URLInfo["query"];
$ok = false;
$conn = @fsockopen($URLInfo["host"], 80, &$errno, $errstr, 15);
if ($conn) {
$host = $URLInfo["host"];
fwrite ($conn, "HEAD ".$DocumentPath." HTTP/1.0\r\nHost: $host\r\n\r\n");
$rueckgabe = fgets($conn, 22);
if (stristr($rueckgabe, '30')) { $ok = true; }
if (stristr($rueckgabe, '20')) { $ok = true; }
fclose($conn);
}
if($ok)
{ header("Location: $URL");
header("Connection: close");
}
else
{
openDB();
$sql = "UPDATE links SET fehler = fehler + 1 WHERE id=".$id.";";
mysql_query($sql) OR die(mysql_error());
closeDB();
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$_SERVER['HTTP_REFERER']);
header("Connection: close");
}
?>