PHP uses curl to determine that page 404 does not exist the original method

Source: Internet
Author: User
Tags php database php regular expression
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.

  • Related Article

    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.