This one's stupid, but it uses
the common class.curl.php, and does a select based upon the error, so you can add different features/functions for 403s, 500s, etc.. Mostly, I'm just lazy and didn't figure it deserved OOP, even if I'm using an OOP class. Enjoy.
Code:
<html>
<head>
<Title>404 Test Thingy or whatever</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff">
<br>
<form method="post">
<div align="center"><strong>Test URLs:</strong><br>
<textarea name="urls" id="urls" cols="45" rows="5"><?=isset($_REQUEST['urls'])?$_REQUEST['urls']:"";?></textarea>
<br>
<input type="submit" name="submit" id="submit" value="Check Response">
</div>
</form>
<?php
// This is hardly an example of good PHP. Ugh.
@require_once("class.curl.php");
// trim() to get rid of errant enter keys.
$myurls = (isset($_REQUEST['urls'])?explode("\n", trim($_REQUEST['urls'])): array());
foreach ($myurls as $url) {
// use our cURL class.
$curlInit = new curl($url);
// Make sure we don't follow redirects.
$curlInit->setopt(CURLOPT_FOLLOWLOCATION, FALSE) ;
// Do it.
$curlInit->exec();
// If we returned a connection error, say so.
if ($myError = $curlInit->hasError()) {
echo "ERR: $url ($myError)<br>\n";
} else {
// Reinit our array
$status = array();
// Seems to have worked, parse it.
if (is_array($curlInit->m_status))
$status = $curlInit->m_status;
// Simple error checking.
if (!empty($status)) {
switch($status["http_code"]) {
case "404":
echo "<font color='red'>404</font>: <a href='$url' target='_new'>[link]</a> $url<br>\n";
break;
default:
// Do nothing if not 404, I guess.
break;
}
}
}
// We're done, close the socket.
$curlInit->close();
} ?>
</body>
</html>