link-checking

What is the best way to check if a URL exists in PHP?

萝らか妹 提交于 2019-12-17 04:01:57
问题 What is the best way to see a URL exists and the response is not a 404 ? 回答1: You can use get_headers($url) Example 2 from Manual: <?php // By default get_headers uses a GET request to fetch the headers. If you // want to send a HEAD request instead, you can do so using a stream context: stream_context_set_default( array( 'http' => array( 'method' => 'HEAD' ) ) ); print_r(get_headers('http://example.com')); // gives Array ( [0] => HTTP/1.1 200 OK [Date] => Sat, 29 May 2004 12:28:14 GMT

Check link works and if not visually identify it as broken

自古美人都是妖i 提交于 2019-12-10 10:23:04
问题 I am working on a project which lists file sharing urls from the likes of Oron, filespost, depositfiles etc that reports sharing of copyrighted materials to identified content owners and rights holders in my network. To better improve the service, which currently stands at a table populated from MySQL database with some filters built in to the php, I want to be able to identify the links that have ceased to function. My thoughts are that when the data is retrieved from the MySQL database the

What is the best way to check if a URL exists in PHP?

这一生的挚爱 提交于 2019-11-26 17:45:52
What is the best way to see a URL exists and the response is not a 404 ? You can use get_headers($url) Example 2 from Manual: <?php // By default get_headers uses a GET request to fetch the headers. If you // want to send a HEAD request instead, you can do so using a stream context: stream_context_set_default( array( 'http' => array( 'method' => 'HEAD' ) ) ); print_r(get_headers('http://example.com')); // gives Array ( [0] => HTTP/1.1 200 OK [Date] => Sat, 29 May 2004 12:28:14 GMT [Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux) [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT [ETag] => "3f80f