Rob/Beth,

The code should also consider:

1 updating the db if the link is 'valid', ie if previously it had been
'down'!
2 putting an @ to prevent any errors causing a hard-stop at the fopen line
3 that the url/database must contain protocol information, ie
http://www.nytimes.com not www.nytimes.com.

Thanks for the discussion,
=dn


> 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/nrc.net/www/robert/links4.php on line 11
> >
> >If someone can tell me what I'm doing wrong, I'd appreciate it.
> >
> >Thanks,
> >    Robert
> >
> >
> >
> >
> >
> 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:
>
> <?php
>
>     $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>";
>
>         }else{
>
>         echo "<p>".$linkdata['linkurl']." is invalid. Updating
> database... ";
>
>             $SQL = "UPDATE links SET status = 0 WHERE linkID =
> '".$linkdata['linkID']."'";
>                 $result2 = mysql_query($SQL);
>             if($result2)
>                 {
>                     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
> --
> http://bethanoia.dyndns.org
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to