PHP curl can simulate an http request from the server, such as web page capture and simulated login. According to the option settings, you can get the response header and body in the returned result of curl_exec, but is there no response status. To obtain the status, you must run curl_exec and then use curl_getinfo.
For example:
The Code is as follows: |
Copy code |
$ Ch = curl_init (); Curl_setopt ($ ch, CURLOPT_URL, 'HTTP: // www. bKjia. c0m '); Curl_setopt ($ ch, CURLOPT_TIMEOUT, 200 ); Curl_setopt ($ ch, CURLOPT_HEADER, FALSE ); Curl_setopt ($ ch, CURLOPT_NOBODY, FALSE ); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE ); Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, FALSE ); Curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'get '); Curl_exec ($ ch ); $ HttpCode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE ); |
In addition, curl_getinfo can obtain many other information.