I am trying to check a huge list of urls/webpages for specific words. For the most part, what I am using below seems to be working but I was wondering how I can get it to error out if the specific path ($stuff[path]) isnt there i.e. 404. fsockopen will error if it cant open the domain itself, but I really need to know if the target page is in error.
Also, since this is my first time really trying this type of thing.... am I doing it the right way or is there a better, more efficient way of doing it?
Thanks in advance.
while ($gal = mysql_fetch_array($result)){
$error = "<font color=green>Ok</font>";
$stuff = parse_url($gal[url]);
$fp = fsockopen ($stuff[host], 80, $errno, $errstr, 5);
if (!$fp) {
$error = "$errstr ($errno)";
} else {
fputs ($fp, "GET /$stuff[path] HTTP/1.0\r\n\r\n");
while (!feof($fp)) {
$open = htmlspecialchars(fgets($fp, 1024));
// word checking
$badword = substr_count($open, "terror");
if($badword){
$error = "<font color=red>Bad Word Found</font>";
}
}
fclose ($fp);
echo $gal['id'] . "=" . $gal['url'] . " = $error<br>";
flush();
}
}