Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checking a url exists

0 views
Skip to first unread message

mindwarp

unread,
Jul 12, 2006, 11:46:15 AM7/12/06
to
Hi,

I've looked on this newsgroup on google and on php.net, but I can find
a work function which will allow me to check if a url exists?

Can anyone provide me with one?
or point we towards one?

Best regards,

Jules.

ImOk

unread,
Jul 12, 2006, 11:56:34 AM7/12/06
to
I dont have code for this but you can do it fairly easily with sockets.
(see php docs)

1) create a socket resource
2) connect to the socket on port 80
3) send the URL
4) read the response.

Check for errors on each of the steps above

mindwarp

unread,
Jul 12, 2006, 12:08:09 PM7/12/06
to
Hi,

I've had a few attempts and always come up with a 200 return code.
I guess 404 handling pages are causing this.


Jules.

mindwarp

unread,
Jul 12, 2006, 12:28:02 PM7/12/06
to
For example...

<?php

$url = 'http://www.whatever.com/ccc';

$fp = @fopen($url, 'r');

if ($fp) {

$headers = stream_get_meta_data($fp);

print_r($headers);


}

Krustov

unread,
Jul 12, 2006, 1:21:34 PM7/12/06
to
<comp.lang.php>
<mindwarp>
<12 Jul 2006 08:46:15 -0700>
<1152719175.2...@35g2000cwc.googlegroups.com>

> I've looked on this newsgroup on google and on php.net, but I can find
> a work function which will allow me to check if a url exists?
>
> Can anyone provide me with one?
> or point we towards one?
>

$skunk="http://www.emailuser.co.uk";
if (fopen($skunk,'r')===FALSE) {exit;}

Although it doesnt work if the website uses a custom 404 webpage and i
never got around to doing any more work on it .


--
Encrypted email address
www.emailuser.co.uk/?name=KRUSTOV

mindwarp

unread,
Jul 12, 2006, 1:57:43 PM7/12/06
to
hi,

yes, i want to cater for custom 404 pages

:(

Jules.

0 new messages