rendered paste body // Gets the Server Headers for the given URL
function getHeaders($url) {
while ($code != 200) {
$options = array(
'allowRedirects' => false,
'maxRedirects' => 0);
$r = new HTTP_Request($url,$options);
$r->setMethod(HTTP_REQUEST_METHOD_GET);
$r->sendRequest();
$page = $r->getResponseBody();
$page = strtolower($page);
$code = $r->getResponseCode();
if(!$page) {
echo '<font color="#ff0000">No Web Server Found</font>';
exit();
}
if ($code === 404) {
echo '<font color="#ff0000">404 Not Found</font>';
exit();
}
echo '<b>Server Code: </b>' .$code. '<br />';
foreach ($r->getResponseHeader() as $name => $value) {
echo '<b>' .$name. ': </b>' .$value. '<br />';
}
$redirectLoc = $r->getResponseHeader('location');
if (preg_match("/http\:\/\/.*$/",$redirectLoc,$matchedUrl)) {
$url = $matchedUrl[0];
} elseif (preg_match("/https\:\/\/.*$/",$redirectLoc,$matchedUrl)) {
$url = $matchedUrl[0];
} elseif (preg_match("/https\:\/\/[^\/]*/",$url,$matchedUrl)) {
$url = $matchedUrl[0]."/".$redirectLoc;
} else {
$url = preg_match("/http\:\/\/[^\/]*/",$url,$matchedUrl);
$url = $matchedUrl[0]."/".$redirectLoc;
}
echo '<br />';
}
}