Home > Backend Development > PHP Tutorial > How to use curl to determine webpage 404 (does not exist) in PHP. Original, curl404_PHP tutorial

How to use curl to determine webpage 404 (does not exist) in PHP. Original, curl404_PHP tutorial

WBOY
Release: 2016-07-12 08:49:52
Original
1242 people have browsed it

How PHP uses curl to determine web page 404 (does not exist) Original, curl404

This article describes how PHP uses curl to determine web page 404 (does not exist). Share it with everyone for your reference, the details are as follows:

<&#63;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.bkjia.com/asdasd.html";
 if(chkurl($url)==true){
     echo "存在";
 }else{
     echo "不存在";
 }
&#63;>

Copy after login

The operation result is: does not exist

Supplement: For HTTP request header information, please refer to the online tool on this site:

HTTP status code list:
http://tools.jb51.net/table/http_status_code

PS: The editor here recommends a PHP formatting and beautifying typesetting tool on this website 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 format php code:

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 operating office document skills (including word, excel, access, ppt)", "PHP array ( Array) operating skills collection", "php sorting algorithm summary", "php common traversal algorithms and techniques summary", "php data structure and algorithm tutorial", "php programming algorithm summary", "php regular expression usage summary", "Summary of PHP operations and operator usage", "Summary of PHP string usage" and "Summary of common PHP database operation skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1136613.htmlTechArticlephp uses curl to determine the method of web page 404 (does not exist) original, curl404 This article tells an example of php using curl to determine web page 404 (does not exist) method. Share it with everyone for your reference, the details are as follows...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template