Is it possible to read HTTP response header data in ASP / PHP?
-
1Do you mean the response or the request headers?Pekka– Pekka2011-05-06 08:55:07 +00:00Commented May 6, 2011 at 8:55
-
2Do you mean either ASP or PHP, or both ASP and PHP?user142019– user1420192011-05-06 08:55:35 +00:00Commented May 6, 2011 at 8:55
-
I mean the response that the server sends after the request. Reading header data using ASP or PHP, not both.Joe– Joe2011-05-06 09:05:01 +00:00Commented May 6, 2011 at 9:05
-
You'd be best using some form of reverse proxy to get this, neither PHP or ASP can directly control the response headers as they're sent via the server itself.Rudi Visser– Rudi Visser2011-05-06 09:10:21 +00:00Commented May 6, 2011 at 9:10
-
I can analyze the response data...Joe– Joe2011-05-06 09:11:04 +00:00Commented May 6, 2011 at 9:11
2 Answers
Neither PHP or ASP directly control the response headers that the web server will return to the client.
In order to actually get this information realiably you'd be best off using some type of reverse proxy, although I'm not sure you'd be able to script this.
The reason being that this is the only way you'd get the actual response headers coming from the server. ASP / PHP both deal with the request, and pass back their response to the server, the server software is then free to do whatever it wants with this data, and can choose to completely ignore anything coming from the scripting language if it wishes to (although, of course, this is highly unlikely!).
An example of PHP not being able to directly control all headers would be this:
<?php
header("Server: Custom-Server-1.0");
This won't work, and the server hostname would still be returned as Apache (or whatever), just tested this (OSX Apache 2.2). I'm hoping I'm right and this won't do anything on other platforms either ;-)
EDIT: In PHP, you could look at the headers_list method, and if using Apache, apache_response_headers, but what I've said before still applies. The values returned from these methods may not be concrete, nor even show the complete headers returned to the client.
Again you're able to confirm this by using doing a request, print_r the return of these functions and then look at the response headers via a tool such as Fiddler, Dragonfly or Firebug.
Comments
Yes. Use this:
Request.Headers["HeaderName"]
Hope this helps. Cheers
EDIT: Need to read the sent headers?
Response.Headers["HeaderName"]