a gallery checker that i wrote the other day:
PHP Code:
<?php
set_time_limit(600);
echo "CHECKING<br><br><br>\n";
$urls = file("galleries.txt");
$safelist = Array();
for ($i = 0; $i < sizeof($urls); $i++)
{
$line = $i+1;
$url = trim($urls[$i]);
$url_arr = parse_url($url);
$header = get_headers($url_arr[host],$url_arr[path]);
$safe = 1;
if (!$header)
{
echo "Line <strong>$line</strong> - Url: $url - <strong>Connection Failed or Timed Out</strong><br><br>\n";
$safe=0;
}
else
{
for ($j = 0; $j < sizeof($header); $j++)
{
if ($j == 0 && ereg("404", $header[$j]))
{$safe=0;echo "Line <strong>$line</strong> - Url: $url - <strong>404</strong> Header found - Full header:<br><small>" . (implode("<br>",$header)) . "</small><br><br>\n";}
else if ($j == 0 && ereg("302", $header[$j]))
{$safe=0;echo "Line <strong>$line</strong> - Url: $url - <strong>302</strong> Header found - Full header:<br><small>" . (implode("<br>",$header)) . "</small><br><br>\n";}
if (ereg("^Location:",$header[$j]))
{$safe=0;echo "Line <strong>$line</strong> - Url: $url - <strong>Forwards</strong> to $header[$j]<br><br>\n";}
}
}
if ($safe) array_push($safelist,$url);
}
$safelist = array_unique($safelist);
echo "<br><br>
SAFE LIST<br><br>\n" . (implode("<br>\n",$safelist));
function get_headers($host, $path = "/")
{
$fp = fsockopen ("$host", 80, &$errnr, &$errstr);
if (!$fp) return 0;
socket_set_timeout($fp, 5); // TIMEOUT SET TO 5 SECONDS
$request_header = "GET $path HTTP/1.1
Accept: */*
Accept-Language: en-us
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)
Host: $host
Connection: close
";
fputs($fp,$request_header);
for ($i=0;!$end;$i++)
{
$line = fgets($fp, 2048);
if (trim($line) == "")
$end = true;
else {
$header[$i] = $line;
}
}
fclose($fp);
return $header;
}
?>
it's kinda slow because it allows up to 5 seconds connection timeout per gallery (you can change it in the code) . i have over 200 galleries in a file and it takes about 3 minutes to check all.
the script will output 404, forwarding, or broken gallery links with detailed info, then it will output a list of safe galleries.
cheers,
Lane