Php uses curl to determine whether a webpage 404 (does not exist) method is original, curl404

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.