Forum Moderators: coopster

Message Too Old, No Replies

Return HTTP status code

         

onetry

5:18 pm on Apr 15, 2007 (gmt 0)

10+ Year Member



I guess if it is possible to obtain a HTTP response code (200 or 404) without fopening entire remote page.

www.example.com/a.php --> 200 THEN fopen()
www.example.com/b.php --> 404 THEN die()

I so would like to low overhead of server.

Any help appreciated. Regards.

[edited by: eelixduppy at 7:56 pm (utc) on April 15, 2007]
[edit reason] example.com [/edit]

borntobeweb

12:33 am on Apr 16, 2007 (gmt 0)

10+ Year Member



You can do this with CURL functions:

$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//$status_code contains the HTTP status: 200, 404, etc.

But I've found that some sites return a 403 when I set CURLOPT_NOBODY to true, also I've just started doing this so there may be more caveats.

onetry

8:24 am on Apr 16, 2007 (gmt 0)

10+ Year Member



Thank you very much :-)

davidyin

10:41 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



Thank you very much. It solve my problem.