We are executing below curl call from PHP.
$url = $fullurl;
if (isset($url)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
$check_url_status = $headers['http_code'];
if ($check_url_status == '200')
$ress = "Link Works";
else
$ress = "Broken Link";
}
What other HTTP status codes should we consider to check if the URL is not a broken /dead link.
Remember the 5 HTTP Status code classes : 1xx Continue (protocol switching), 2xx OK, 3xx Redirect, 4xx client error, 5xx server error.
If your Curl client follow the redirections (3xx), I think you can just test that status code <= 299. All other status code will make a "broken link".
Depending on how deep is your test, you can also think of theses cases :
If your goal is to change the display of a broken link you can use Javascript to manage it client-side, but it can be limited to your domain. See this question