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 ”—————————————————\nHTTP Check Headers Script (Written by Tully Rankin)\nUsage: headers.php [site] [get|head|options] file\nExample: 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.1\r\n”; $out .= ”Host: $site\r\n”; $out .=”Connection: Close\r\n\r\n”;} else if ($request == ”options”) { $out = ”OPTIONS $file HTTP/1.1\r\n”; $out .= ”Host: $site\r\n”; $out .=”Connection: Close\r\n\r\n”;} else if ($request == ”head”) { $out = ”HEAD $file HTTP/1.1\r\n”; $out .= ”Host: $site\r\n”; $out .=”Connection: Close\r\n\r\n”;} else { echo ”Incorrect Request Type\n”; 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); } ?>