Getting HTTP header in ASP/ PHP
Is it p开发者_如何学Cossible to read HTTP response header data in ASP / PHP?
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.
Yes. Use this:
Request.Headers["HeaderName"]
Hope this helps. Cheers
EDIT: Need to read the sent headers?
Response.Headers["HeaderName"]
精彩评论