Home >Backend Development >PHP Tutorial >How to use curl to determine if the webpage 404 does not exist in PHP Original
The example in this article describes how PHP uses curl to determine the 404 (does not exist) page. Share it with everyone for your reference, the details are as follows:
<?php /* php使用curl判断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);//设置超时时间 curl_exec($handle); //检查是否404(网页找不到) $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 "存在"; }else{ echo "不存在"; } ?>
The operation result is: does not exist
Additional: Regarding HTTP request header information, you can refer to the online tool of this site:
HTTP status code encyclopedia:
http://tools.jb51.net/table/http_status_code
PS: The editor here recommends a PHP formatting and beautifying typesetting tool on this site to help you code typesetting in future PHP programming:
php code online formatting and beautification tool:
http://tools.jb51.net/code/phpformat
In addition, since php belongs to the C language style, the following tool can also implement php code Formatting:
C language style/HTML/CSS/json code formatting and beautification tool:
http://tools.jb51.net/code/ccode_html_css_json
Readers who are interested in more PHP related content can Check out the special topics on this site: "Summary of PHP mathematical operation skills", "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Complete of PHP array (Array) operation skills", "Summary of PHP sorting algorithm", "Summary of Common PHP Traversal Algorithms and Techniques", "PHP Data Structure and Algorithm Tutorial", "Summary of PHP Programming Algorithms", "Summary of PHP Regular Expression Usage", "Summary of PHP Operations and Operator Usage", "php String (string) usage summary" and "php common database operation skills summary"
I hope this article will be helpful to everyone in PHP programming.
The above introduces how PHP uses curl to determine that the webpage 404 does not exist. It is original and includes relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.