I have a database with links to external sites. But when someone clicks on a link to spawn that site I check to the site to see if it is a valid link because I dont want to show a user a File not found link, because someone elses server is down or the link has been removed.
So this is what I do
$output=implode("\n",file($output));
if ((strlen($output)>0)&&(strpos($output,"HTTP 404")<1))
{
//goto the link
}
else
{
//redirect to my own custom error.
}
So right now its loading the contents of that entire site into a variable and then parsing through it to see if its ok or not. It works for most cases but probably not all.
I was wondering if anyone knows a better way to check if a link is valid before going to it.
Thanks