Tool for getting headers of a web document

Since there are more response codes that may be returned by a web document, this tool allows you to check them. Sometimes a 404 page (page not found) returns code 200 which actually means "OK", sometimes permanent or temporary redirects aren’t setup properly, so here below is a tool that does a simple and fast check. The tool below needs full URL, however if http:// or https:// prefix isn’t included, http:// is being added into the string.

HTTP response header is a text information that a server sends back to a client after an HTTP request that is sent from client to a server is processed.

 

Code example

<?php //function to return headers of a web document //allow_url_include = On must be included in php.ini if(!function_exists(’get_contents’)) { function get_contents($in) { file_get_contents($in); $hc = count($http_response_header); for($i=0;$i<$hc;$i++) $ret[] = $http_response_header[$i]; return $ret; } } //application to echo headers of a web document $str[] = "http://www.dmoz.org"; //secure the input in case there’s no http or https prefix if( (@strpos($str[0],"http://")===false) && (@strpos($str[0],"https://")===false) ) $str[0] = "http://".$str[0]; //secure second time while(@strpos($str[0],"http:///")!==false) $str[0] = str_replace("http:///","http://",$str[0]); $output = get_contents(htmlspecialchars(stripslashes($str[0]))); //echo beginning of output echo "<div><h2>The result is following</h2><div id=\"qry_output\">"; $output_count = count($output); //let’s echo entire headers for($i=0;$i<$output_count;$i++) echo "<p>".$output[$i]."</p> "; echo "</div></div>"; ?>

Other tools & help

If you need help with PHP scripting, Apache setup and server-related situations, drop me a line. You’re also welcome to visit other tools - they’re listed below.