check broken link/url in php

In this pose we can check check broken link/url in php. In this post we can check url, image url, pdf url, xml url. It is very easy method for check url is broken or not.

200 OK

200 request has succeeded. The information returned with the response is dependent on the method used in the request GET, HEAD, POST, TRACE.

GET = GET is an entity corresponding to the requested resource is sent in the response.

HEAD = HEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body.

POST = POST an entity describing or containing the result of the action.

TRACE = TRACE an entity containing the request message as received by the end server.

function check_url($test_url) {
    $ch_init = curl_init();
    curl_setopt($ch_init, CURLOPT_URL, $test_url);
    curl_setopt($ch_init, CURLOPT_HEADER, 1);
    curl_setopt($ch_init , CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch_init);
    $headers_result = curl_getinfo($ch_init);
    curl_close($ch_init);


    return $headers_result['http_code'];
}

$test_url = "http://onlinecode";
$check_url_result = check_broken_url($test_url);
if ($check_url_result == '200')
{
	echo "This is Working Link.";
}
else
{
	echo "This is Broken Link.";
}

check url is exist in php

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  49  =  55

We accept paid advance and paid guest Posting on our Site : Contact US