Learn how to see if a URL is valid. and still alive or if it's a 404 Not Found You have a thousands of links just randomly lying around from back in the day and you want to only put the ones up which still exist, and not the ones which don't exist anymore, what do you do? Answer: Not a problem bub, just use the power of PHP by using the fsockopen() function to check and see if the site is up and you'll be set: <? $up = @fsockopen("www.spoono.com", 80, $errno, $errstr, 30); if($up) { echo "<a xhref=\"http://www.spoono.com\">Spoono</a>"; } else { echo "<a xhref=\"http://www.spoono.com\">Spoono's Dead!! :(</a>"; } ?>
The code is fairly simple and easy to follow. The fsockopen() function actually tries to connect a socket to the listed site. The first parameter listed "www.spoono.com" would be the URL of the website you want to check. It is important that you do not put http:// in front of the URL or else the script does not work. The second parameter, 80, would be the port, which should just be left alone. The next two parameters are just standard PHP errors, and the last one, 30, is the amount of time to wait in seconds before assuming its a timeout. The next few lines checks to see if the connection went through and if it did then put the link up. Again, an easy and useful script. Well, that's all folks. Not too tough was it? Well thats it folks. I hope it works out for you and if it doesn't, post on the board and we'll try to help you out.
|