Php uses curl to determine whether a webpage 404 (does not exist) method is original, curl404
This example describes how php uses curl to determine the web page 404 (does not exist. We will share this with you for your reference. The details are as follows:
<? Php/* php uses curl to determine 404 * Created on 2016-6-22 * Writer www.jb51.net */function chkurl ($ url) {$ handle = curl_init ($ url); curl_setopt ($ handle, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt ($ handle, CURLOPT_CONNECTTIMEOUT, 10); // set the timeout value curl_exec ($ handle); // check whether the timeout value is 404 (the webpage cannot be found) $ httpCode = curl_getinfo ($ handle, CURLINFO_HTTP_CODE); if ($ httpCode = 404) {return false;} else {return true;} curl_close ($ handle ); } $ Url = "http://www.bkjia.com/asdasd.html"; if (chkurl ($ url) = true) {echo "exists";} else {echo "doesn't exist" ;}?>
The running result is: nonexistent.
For more information about HTTP request headers, see online tools on this site:
HTTP status code Daquan:
Http://tools.jb51.net/table/http_status_code
PS: I recommend a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:
Php code online formatting and beautification tools:
Http://tools.jb51.net/code/phpformat
In addition, because php belongs to the C language style, the following tool can also format php code:
C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json