HTTP Header Viewer... Do I need regexps?
| From: | Leif Gregory | Date: | Wed, 28 Apr 2004 15:31:07 +0000 |
| Subject: | HTTP Header Viewer... Do I need regexps? | ||
| Groups: | php.general php.windows | ||
| Request: | Send a blank email to php-windows+get-23570@lists.php.net to get a copy of this message | ||
Hello everyone,
I've been putzing with this for about a week on and off now.
I've googled like crazy and tried to figure out the regexps, but I
can't just get it.
What I'm doing is taking some code I found to show me the HTTP
headers from a remote server and making it a bit more dynamic with a
runtime input, and to format the output nicely. I can retrieve the
headers just fine, but I can't get the output broken out into pieces
from the returned single line.
i.e.
HTTP/1.1 200 OK Date: Tue, 20 Apr 2004 17:28:23 GMT Server: Microsoft-IIS/5.0 Last-modified: Thu,
01 Jan 2004 19:56:39 GMT Connection: close Content-type: text/html
I want to format it as such by breaking each line into its own
array element:
HTTP/1.1 200 OK
Date: Tue, 20 Apr 2004 17:28:23 GMT
Server: Microsoft-IIS/5.0
Last-modified: Thu, 01 Jan 2004 19:56:39 GMT
Connection: close
Content-type: text/html
Any help would really be appreciated.
BTW, this is PHP 4.3.4 on Win2K Pro running under Sambar.
Here's the code:
,------ [ ]
| <HTML>
| <HEAD>
| </HEAD>
| <BODY>
|
| This will return the HTTP headers for a site to determine SERVER type, cookies, sessions etc.
| <br><br>
|
| <form>
| <input type="text" name="URL" value="URL">
| <input type="SUBMIT" name="SUBMIT">
| </form>
|
| <?
| if (isset($_GET['URL']))
| {
| $fp = fsockopen ($_GET['URL'], 80, $errno, $errstr, 30);
| if (!$fp)
| {
| echo "$errstr ($errno)<br>\n";
| }
| else
| {
| fputs($fp, "GET / HTTP/1.0\r\nHost: " . $_GET['URL'] .
"\r\n\r\n");
|
| //This part allows me to see the headers but on a single line
| //while (!feof($fp))
| //{
| // echo fgets($fp,256);
| // }
| //fclose ($fp);
| //}
|
| //This is the part I can't figure out
| preg_match_all ("Date:\s*.*?\s\S*:\s*|\z", fgets($fp,256), $server);
| echo $server;
| fclose($fp);
| }
|
|
| //Some other stuff I tried.
| //preg_match_all ("/HTTP.*?K/", fgets($fp,256), $server);
| //echo $server[1];
| //fclose($fp);
| //}
| //echo "Method: " . substr("$pagedata", 0, 15) . "<br
/>";
| //echo substr("$pagedata", 16, 36) . "<br />";
| //echo substr("$pagedata", 52, 67) . "<br />";
|
| }
|
| ?>
| </BODY>
| </HTML>
`----------
Tagline of the day:
The problem with paradigms is that shift happens.
--
Leif (TB lists moderator and fellow end user).
Using The Bat! 2.10 RC/1 under Windows 2000 5.0
Build 2195 Service Pack 4 on a Pentium 4 2GHz with 512MB