Grabbing HTTP Header

Dave Cragg dcragg at lacscentre.co.uk
Mon May 5 04:52:01 EDT 2003


At 6:23 pm -0700 4/5/03, Dan Shafer wrote:
>OK, I give up. What's the function/method/magic incantation to grab
>the incoming HTTP header in the MC CGI?
>
>I know what to do with this info once I have it but I'm darned if I
>can find any reference to anything resembling HTTP headers.

I don't think there is a way to get all the headers at one time. But 
the headers are exported to environment variables by the http server. 
You can access these directly. I assume this is done according to the 
CGI standard.

For some header data, the names of the environment variables is 
predetermined. For example:


$REQUEST_URI
$REQUEST_METHOD
$SERVER_PROTOCOL
$CONTENT_TYPE
$CONTENT_LENGTH

Other environment variables (including custom headers), are formed by 
putting "HTTP_" before the header name (and substituting hyphens with 
underscores). For example:

$HTTP_USER_AGENT
$HTTP_HOST

So if you include the following custom header in your request,

      DansCustomHeader=<some value>

you could retrieve the value of this field in your cgi script by 
getting the $HTTP_DANSCUSTOMHEADER environment variable.

Cheers
Dave



More information about the metacard mailing list