Trx wrote:

> Hi, I'm very much a newbie!
> I'm trying to set up a site which will automatically test links in a large
> link directory and show date and time of last check and whether or not a
> link to the external URL was dead or alive at the time.


the curl library will let you do this. query the link, and then evaluate 
the server's response. but first of all check if you have curl enabled. 
<?php phpinfo(); ?>

then check out the example, two functions i happened to write a few days 
ago, no kidding. ;-)
make sure you are prepared for that the remote server doesn't respond at 
all.

phil.

<?php

echo getHttpStatusCode("http://www.phillipoertel.com/index.html";);

function getHttpHeader($url) {
        
        ob_start(); // send all output to a buffer instead of being displayed
        $ch = curl_init();
        
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_NOBODY, 1);
        // you could probably achieve the same with the following line.
        # curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "HEAD / HTTP/1.0");

        curl_exec($ch);
        curl_close ($ch);

        // put all buffered output into $header
        $header = ob_get_contents();
        ob_end_clean();
        
        return $header;
}

function getHttpStatusCode($url) {
        
        $header = getHttpHeader($url);
        // grab only first line of the header
        list($status) = explode("\n",$header);
        $code = explode(" ",$status);
        return $code[1];

}

?>

HTTP Status Codes:
*************
100 Continue
101 Switching Protocols
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
300 Multiple Choices
301 Moved Permanently
302 Moved Temporarily / Found
303 See Other
304 Not Modified
305 Use Proxy
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Time-Out
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URL Too Large
415 Unsupported Media Type
500 Server Error
501 Not Implemented
502 Bad Gateway
503 Out of Resources
504 Gateway Time-Out
505 HTTP Version not supported



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to