0

Is it possible to read HTTP response header data in ASP / PHP?

6
  • 1
    Do you mean the response or the request headers? Commented May 6, 2011 at 8:55
  • 2
    Do you mean either ASP or PHP, or both ASP and PHP? Commented 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. Commented 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. Commented May 6, 2011 at 9:10
  • I can analyze the response data... Commented May 6, 2011 at 9:11

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes. Use this:

Request.Headers["HeaderName"]

Hope this helps. Cheers

EDIT: Need to read the sent headers?

Response.Headers["HeaderName"]

3 Comments

I think you're talking about headers from the browser's request. He is asking for a way to read the RESPONSE headers that the server will output if i understood...
Agh, just posted the PHP version then realised he's looking for response headers.
Thanks Edgar, I was looking for reading the response header, but reading the request header might be useful too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.