emehrkay Posted May 23, 2007 Share Posted May 23, 2007 i have a url and i want to check to see if the page exists or is not giving back a 404 or whatever error, what functions handle this? does anyone know of any prebuilt classes that may take care of these type transactions? thanks Link to comment https://forums.phpfreaks.com/topic/52652-what-are-the-functions-that-allow-you-to-check-the-response-from-a-given-url/ Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 Take a look at curl. Link to comment https://forums.phpfreaks.com/topic/52652-what-are-the-functions-that-allow-you-to-check-the-response-from-a-given-url/#findComment-259892 Share on other sites More sharing options...
radar Posted May 23, 2007 Share Posted May 23, 2007 You could use the file exists deal though often times that will return false for everything for an external url... you might try taking a look at the get_headers function if you have php5, as i don't believe it was included in php4 http://us4.php.net/manual/en/function.get-headers.php Also you could do a HEAD request to the URL using a socket, if you get a 200 it's there. If you get something else it might not be (maybe it's a redirect (301 IIRC)). and here is some sample code for you on that just in case you are unware of how to use the sockets.. <?php if($sock=fsockopen('hostname.tld',80)) { fputs($sock, "HEAD /foo HTTP/1.0\r\n\r\n"); while(!feof($sock)) { echo fgets($sock); } } ?> You can disect an url with parse_url to get the hostname/port/path from a URL. You might want to do HTTP/1.1 request (where a Host: header is required) Hope it helps. Link to comment https://forums.phpfreaks.com/topic/52652-what-are-the-functions-that-allow-you-to-check-the-response-from-a-given-url/#findComment-259895 Share on other sites More sharing options...
emehrkay Posted May 23, 2007 Author Share Posted May 23, 2007 thanks guys, i will explore both of these Link to comment https://forums.phpfreaks.com/topic/52652-what-are-the-functions-that-allow-you-to-check-the-response-from-a-given-url/#findComment-259897 Share on other sites More sharing options...
radar Posted May 23, 2007 Share Posted May 23, 2007 btw -- i used "are" in my code for reading sake (if you try that) -- it should be "r" -- but being a recommended proficient i hope you knew that Link to comment https://forums.phpfreaks.com/topic/52652-what-are-the-functions-that-allow-you-to-check-the-response-from-a-given-url/#findComment-259923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.