This example describes how PHP uses Curl to determine page 404 (which does not exist). Share to everyone for your reference, as follows:
<?php/* PHP uses curl to judge 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 timeout time curl_exec ($handle); Check if 404 (Web page not found) $httpCode = Curl_getinfo ($handle, curlinfo_http_code); if ($httpCode = = 404) { return false; } else{ return true; } Curl_close ($handle); } $url = "http://www.jb51.net/asdasd.html"; if (Chkurl ($url) ==true) { echo "exists";} else{ echo "does not exist";}? >
The result of the operation is: not present
Add: For HTTP request header information, refer to the online tool:
HTTP status Code Daquan:
Http://tools.jb51.net/table/http_status_code
PS: Small series here recommend a site of the PHP format of the beautification of the layout tools to help you in the future of PHP programming code layout:
PHP Code online format Beautification tool:
Http://tools.jb51.net/code/phpformat
In addition, because PHP is a C language style, the following tool can also be used to implement the PHP code format:
C Language Style/html/css/json code formatting beautification tool:
Http://tools.jb51.net/code/ccode_html_css_json
More interested in PHP related content readers can view the site: "PHP Math Skills Summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP array" operation Skills Daquan, " PHP Sorting algorithm Summary, "PHP Common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string Usage Summary" and " A summary of common PHP database operation techniques
I hope this article is helpful to you in PHP programming.
The above is the introduction of PHP using curl to determine that page 404 does not exist in the original method, including the content, I hope that the PHP tutorial interested in a friend helpful.