Not sure how to supress the warning message that PHP automatically does
when you haven't got a valid URL though.
should be able to surpress errors by adding an * before the result variable
*$fp = fopen($linkdata['linkurl'],"r");
Hope this helps--or even works for this particular problem.
Hugh
----- Original Message -----
From: "Beth Gore" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, November 30, 2002 11:02 AM
Subject: Re: [PHP] Test links?
> 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