This is a simple script I wrote to do GET/OPTIONS/HEAD requests to a website. It’s a command line PHP script which uses fsockopen to connect to the server. This comes in handy when you need to see headers received from a website. Also, it’s good to see what is returned by the OPTIONS directive.
<?php
if ($argc < 4) {
echo "
---------------------------------------------------n
HTTP Check Headers Script (Written by Tully Rankin)n
Usage: headers.php [site] [get|head|options] filen
Example: headers.php www.example.com get /n
---------------------------------------------------
";
exit;
} else {
$site = $argv[1];
}
$request = strtolower($argv[2]);
$file = $argv[3];
if ($request == "get") {
$out = "GET $file HTTP/1.1rn";
$out .= "Host: $sitern";
$out .="Connection: Closernrn";
} else if ($request == "options") {
$out = "OPTIONS $file HTTP/1.1rn";
$out .= "Host: $sitern";
$out .="Connection: Closernrn";
} else if ($request == "head") {
$out = "HEAD $file HTTP/1.1rn";
$out .= "Host: $sitern";
$out .="Connection: Closernrn";
} else {
echo "Incorrect Request Typen";
exit;
}
$fp = fsockopen($site,80,$errstr,$errno,30);
if (!$fp) {
echo "$errstr ($errno)";
} else {
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 1024);
}
fclose($fp);
}
?>