In PHP, check whether a link exists, there are two methods, one is using curl, the other is
Get the HTTP header of the response code, if it is 200 is OK, if it is 404 can not be found, the example is as follows:
1) Use Get_headers:
<?php $url = "Http://www.abc.com/demo.jpg"; $headers = @get_headers ($url); if ($headers [0] = = ' http/1.1 404 Not Found ') { echo "URL not Exists";} else {
There is a 2nd argument in Get_headers, which is true, the result will be an associative array
2) Use Curl
<?php $url = "Http://www.domain.com/demo.jpg"; $curl = Curl_init ($url); curl_setopt ($curl, Curlopt_nobody, true); $result = curl_exec ($curl); if ($result!== false) { $statusCode = Curl_getinfo ($curl, curlinfo_http_code); if ($statusCode = =) { echo "URL Exists"} } else {
CURLOPT_NOBODY specifies that only the connection is established and the contents of the entire message are not taken.
The above describes the PHP detection links exist code instance sharing, including PHP, instance of the content, I hope the PHP tutorial interested in a friend helpful.