It is often necessary to determine whether a file can be accessed. You can identify it by using the http status code. 200 indicates normal access, and 404 indicates that the page cannot be found. The code is as follows:
|The code is as follows:||Copy code|
$ Address = gethostbyname ($ host );
Socket_write ($ socket, $ request, strlen ($ request ));
$ Response = split ('', socket_read ($ socket, 1024 ));
Another way to get the http status code
To use curl, you must enable it in php. ini> <on a Windows Server, open php. ini and find:
Extension = php_curl.dll
Remove the preceding annotations.
|The code is as follows:||Copy code|
|$ Curl = curl_init ();
$ Url = 'http: // www.111cn.net ';
Curl_setopt ($ curl, CURLOPT_URL, $ url); // sets the URL
Curl_setopt ($ curl, CURLOPT_HEADER, 1); // Get the Header
Curl_setopt ($ curl, CURLOPT_NOBODY, true); // we just need Head
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); // save the data to a string. Don't output it to the screen.
$ Data = curl_exec ($ curl); // start execution ~
Echo curl_getinfo ($ curl, CURLINFO_HTTP_CODE); // I know the HTTPSTAT code ~
Curl_close ($ curl); // when used up, remember to turn it off.
Some status code
1xx: request received, continue processing
2xx: The operation is successfully received, analyzed, and accepted.
3xx: The request must be further processed.
4xx: The request contains an error syntax or cannot be completed
5xx: The server failed to execute a fully valid request.
100 -- the customer must continue to send the request
101 -- the client requests the server to convert the HTTP protocol version according to the request
200 -- Transaction successful
201 -- prompt to know the URL of the new file
202 -- accept and process, but not complete
203 -- the returned information is uncertain or incomplete
204 -- the request is received, but the returned information is null.
205 -- when the server completes the request, the user agent must reset the file that has been browsed.
206 -- the server has completed some users' GET requests
300 -- the requested resources can be obtained in multiple places
301 -- delete request data
302 -- request data found at other addresses
303 -- we recommend that you access other URLs or access methods.
304 -- the client has executed GET, but the file has not changed
305 -- the requested resource must be obtained from the address specified by the server
306 -- code used in HTTP of the previous version, which is not used in the current version
307 -- declaring temporary deletion of requested resources
400 -- Incorrect request, such as syntax error
401 -- authorization request failed
402 -- retain valid ChargeTo header response
403 -- the request is not allowed
404 -- no file, query, or URl found
405 -- the method defined in the Request-Line field is not allowed.
406 -- the requested resource is inaccessible due to the user's Accept drag.
407 -- similar to 401, the user must first be authorized on the proxy server
408 -- the client did not complete the request within the specified time
409 -- the request cannot be completed due to the current resource status
410 -- this resource is no longer available on the server and there is no further reference address
411 -- the server rejects the user-defined Content-Length attribute request
412 -- one or more Request Header fields are incorrect in the current request
413 -- the requested resource is larger than the size allowed by the server
414 -- the requested resource URL is longer than the length allowed by the server
415 -- the requested resource does not support the format of the requested Project
416 -- the request contains the Range request header field, which has no range indication value in the current request resource Range.
It does not contain the If-Range request header field.
417 -- the server does not meet the expectation specified in the header field of the response Ct request. If it is a proxy server, it may be that the next-level server cannot meet the request
500 -- Internal error occurred on the server
501 -- the server does not support the requested function
502 -- the server is temporarily unavailable, sometimes to prevent system overload
503 -- server overload or service suspension
504 -- the gateway is overloaded. The server uses another gateway or service to respond to the user. The waiting time is long.
505 -- the server does not support or reject the specified HTTP version in the request header