Link Rot

Given that websites come and go, links rot. Thus you might want to check your collection of links periodically, to make sure they still work. The script below will tell you if a link still works. Drag and drop a URL into the textbox below or type one in and then hit go.

URL to Check

There are far more sophisticated, recursive, link checking tools out there. DreamWeaver has one built in, as I recall. If you want the version I made, copy and paste from below, but I encourage you to go to the source for a discussion of the technique. The site that provided the source, StackOverflow, identifies itself as a Q&A resource "for professional and enthusiast programmers."

I added the form so you can check a link from a web page. I also added the color coding (trivial coding but maybe helpful usability wise).

<FORM METHOD="POST" action="<?php echo $PHP_SELF; ?>">
URL to Check <input type="text" name="url" value="http://" size="100"></br><br>
<INPUT TYPE="submit" value = "go" name="go">

$go = $_REQUEST['go'];
$url = $_REQUEST['url'];
print "<a href='".$url."'>$url</a> ";

function check_url($url) {
$headers = @get_headers( $url);
$headers = (is_array($headers)) ? implode( "\n ", $headers) : $headers;
return (bool)preg_match('#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers);
if (check_url($url))
echo "<span style="background-color:green;color:white;"> Works ";</span> else
echo "<span style="background-color:red;color:black;"> Broken ";</span> }