Forum Moderators: coopster

Message Too Old, No Replies

PHP Ping a Link - Is link live?

         

username

3:54 am on Jan 28, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi all, I am trying to ping a link to see if it is working. My script works, but there are some weird issues, such as when the $link is [cnn,...] which is broken, it should not allow this through but does, any ideas?

$urlCheck = @fopen($link, 'r');
if($urlCheck == false) {
$error = "SORRY CANNOT FIND LINK!";
}
@fclose($urlCheck);

Thanks in advance...

penders

2:00 pm on Jan 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My script works, but there are some weird issues, such as when the $link is [cnn,...] which is broken,

Are you saying that another broken link such as [thisisabrokenlink.com...] does indeed fail and get caught by your script?

If so, then perhaps you need to do a precheck (with a regexp) to make sure the URL is at least a valid format?

eelixduppy

5:58 pm on Jan 28, 2009 (gmt 0)



Instead of grabbing the whole page using fopen, you can also use cURL to grab the headers (without the content) and check the status. Will save on bandwidth as well as run time. :)