简体   繁体   中英

what http status codes to accept

I'm using Curl to find out the status code of a website. This is in response to a user typing in a url in a form, basically I just want to check the url is valid, so I thought the best way would be to only allow certain codes which are likely to be ok. But this isn't working as well as expected. For EG tesco returns 503, Marks&Sparks a 405. So it seems like there could be a lot more status codes which are in fact ok but which don't seem like they should be ok to me.

So... my question is, what http status codes should I trust. Or should I be doing this the other way round and pass everything except some particular status codes?

For completeness and in case it helps anyone, here's how I'm getting the status code:

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_NOBODY, true);
$result = curl_exec($curl);
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
if ($statusCode == 200 || $statusCode == 300 || $statusCode == 301 || $statusCode == 302 || $statusCode == 303 || $statusCode == 307 || $statusCode ==) {
    $ret = true;   
}

Check Existance of a url through CURL
Refer : http://www.php.net/manual/en/function.file-exists.php#74469

<?php
function url_exists($url) {
    if (!$fp = curl_init($url)) return false;
    return true;
}
?>

Some Status Code and References as per your doubt

200 OK

The request has succeeded. The information returned with the response is dependent on the method used in the request , for example:

GET an entity corresponding to the requested resource is sent in the response;

HEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body;

POST an entity describing or containing the result of the action;

TRACE an entity containing the request message as received by the end server.

201 Created

The request has been fulfilled and resulted in a new resource being created . The newly created resource can be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the resource given by a Location header field.

202 Accepted

The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place. There is no facility for re-sending a status code from an asynchronous operation such as this.

203 Non-Authoritative Information

The returned metainformation in the entity-header is not the definitive set as available from the origin server, but is gathered from a local or a third-party copy. The set presented MAY be a subset or superset of the original version. For example, including local annotation information about the resource might result in a superset of the metainformation known by the origin server. Use of this response code is not required and is only appropriate when the response would otherwise be 200 (OK).

204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

205 Reset Content

The server has fulfilled the request and the user agent SHOULD reset the document view which caused the request to be sent. This response is primarily intended to allow input for actions to take place via user input, followed by a clearing of the form in which the input is given so that the user can easily initiate another input action. The response MUST NOT include an entity.

Read This

http://www.seocentro.com/articles/apache/http-status-codes.html
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM