Jump to content

what are the functions that allow you to check the response from a given url?


emehrkay

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.