This example describes the way PHP uses Curl to judge Web page 404 (nonexistent). Share to everyone for your reference, specific 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 to see if 404 (Web page is 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 run result is: does not exist
Supplemental: For HTTP request header information, refer to the online tools of this site:
Encyclopedia of HTTP Status codes:
Http://tools.jb51.net/table/http_status_code
PS: Small knitting here recommend a site for the layout of the PHP format landscaping tools to help you in the future of PHP programming code layout:
PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat
In addition, because PHP belongs to the C language style, the following tool can also be used to format PHP code:
C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json
More interested in PHP related content readers can view the site topics: "PHP Math Arithmetic Skills summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP Array" operation Skills Encyclopedia, " Summary of the PHP sorting algorithm, "PHP commonly used 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 (String) Usage summary" and " A summary of common PHP database operations tips
I hope this article will help you with the PHP program design.