Introduction to the method of php get_headers to determine whether the URL is valid

WBOY
Release: 2016-07-25 08:59:46
Original
977 people have browsed it
php get_headers can be used to determine whether the URL is valid. This article will give you a brief introduction. Friends in need can refer to it.

Use php get_headers to determine the true validity of the url. For those who have not yet learned about the usage of the php get_headers function, you can refer to the article on this site: Explanation and usage of the php get_headers function. After understanding this function, you can know that this function will return the header information of an HTTP request. The information format is basically as follows: 1), Array ( [0] => HTTP/1.1 200 OK [1] => Date: Sat, 29 May 2004 12:28:13 GMT [2] => Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) [3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT [4] => ETag: "3f80f-1b6-3e1cb03b" [5] => Accept-Ranges: bytes [6] => Content-Length: 438 [7] => Connection: close [8] => Content-Type: text/html )

2), Array ( [0] => HTTP/1.0 404 Not Found [1] => Date: Sat, 29 May 2004 12:28:13 GMT [2] => Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) [3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT [4] => ETag: "3f80f-1b6-3e1cb03b" [5] => Accept-Ranges: bytes [6] => Content-Length: 438 [7] => Connection: close [8] => Content-Type: text/html )

Analysis: If it is judged whether the URL is valid or not, it is judged by the value of the first element in the array. The server returns 200, which means the file is returned correctly, and returns 404, which means the file does not exist. This makes it easy to determine whether a URL exists.

Many times, it is these small functions that help a lot. There are many good gadgets for obtaining header information. The principle is basically the same as this. It is recommended that you firmly grasp the usage of the get_headers() function.



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!