By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Checking a url exists

P: n/a
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.

Jul 12 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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 wrote:
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.
Jul 12 '06 #2

P: n/a
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.

Jul 12 '06 #3

P: n/a
For example...

<?php

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

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

if ($fp) {

$headers = stream_get_meta_data($fp);

print_r($headers);
}

Jul 12 '06 #4

P: n/a
<comp.lang.php>
<mindwarp>
<12 Jul 2006 08:46:15 -0700>
<11**********************@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
Jul 12 '06 #5

P: n/a
hi,

yes, i want to cater for custom 404 pages

:(

Jules.

Jul 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.