Skip to content

Instantly share code, notes, and snippets.

@LeffeBakedBird
Created September 5, 2017 08:47
Show Gist options
  • Save LeffeBakedBird/4b5d390a78990417deac40b8f2ea34d9 to your computer and use it in GitHub Desktop.
Save LeffeBakedBird/4b5d390a78990417deac40b8f2ea34d9 to your computer and use it in GitHub Desktop.
<?php
$counter = 0;
$foundCounter = 0;
$notFoundCounter = 0;
$okCounter = 0;
$unknownCoutner = 0;
$urls = array();
$DomDocument = new DOMDocument();
$DomDocument->load('sitemap.xml');
$DomNodeList = $DomDocument->getElementsByTagName('loc');
foreach($DomNodeList as $url) {
echo $url->nodeValue;
$headers = get_headers($url->nodeValue);
$code = $headers[0];
echo $code;
echo "<br/>";
$counter++;
if ($headers[0] == "HTTP/1.0 302 Found")
{
$foundCounter++;
}
elseif ($headers[0] == "HTTP/1.0 404 Not Found")
{
$notFoundCounter++;
}
elseif ($headers[0] == "HTTP/1.0 200 OK" || $headers[0] == "HTTP/1.1 200 OK")
{
$okCounter++;
}
else
{
$unknownCoutner++;
}
}
echo "<hr/>";
echo "Total URLs: ". $counter ."<br/>";
echo "Total 302 Found: ". $foundCounter ."<br/>";
echo "Total 404 Not Found: ". $notFoundCounter ."<br/>";
echo "Total 200 OK: ". $okCounter ."<br/>";
echo "Other statuses: ". $unknownCoutner;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment