Rob Packer wrote:

Okay, I'm confused... file, fopen, and fsockopen seem to say not found on
alot valid URLs... does this look to be correct usage?
$url = $row[0]; // just get the url from the db
$fp = implode ('', file ($url));
if (!$fp) {echo "<font color=red><b>Unable to access file</b></font>"; }
else { fclose($fp); echo "The link is working!"; }

It seems I always get this warning...

Warning: Supplied argument is not a valid File-Handle resource in
/web/home/ on line 11

If someone can tell me what I'm doing wrong, I'd appreciate it.


When fopen successfully opens a file it populates an array $http_response_header, which you can examine to see if the link works or not - I don't believe you can actually get the file itself, but since that's not what we're after that's not a problem!

Having said that, fopen produces a very annoying error if it doesn't find the page, but I found the following works:


$SQL = "SELECT linkurl, linkID FROM links";
$result = mysql_query($SQL);

while($linkdata = mysql_fetch_array($result)){
$fp = fopen($linkdata['linkurl'],"r");
if($fp) {
echo "<p>".$linkdata['linkurl']." is still valid.</p>";

echo "<p>".$linkdata['linkurl']." is invalid. Updating database... ";
$SQL = "UPDATE links SET status = 0 WHERE linkID = '".$linkdata['linkID']."'";
$result2 = mysql_query($SQL);
echo "Database updated</p>";


Rather than deleting the link, it's probably better to set a flag to show it was invalid last time you checked, but check it again next time. Or you could keep a count of the number of failed attempts, and delete if it goes beyond 3 or so.

Not sure how to supress the warning message that PHP automatically does when you haven't got a valid URL though.

Hope this works for you!

Beth Gore

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to