CGI: how to get referer header?

nihilo exnihilo at NOmyrealCAPSbox.com
Sat Mar 22 16:49:08 EST 2003


Skip Montanaro wrote:
>     exnihilo> I am trying to get the referer and user agent headers in a cgi
>     exnihilo> program I'm writing. I haven't been able to find any clear
>     exnihilo> information on how to do this, but I've been trying the
>     exnihilo> following:
> 
>     exnihilo> referer = cgi.parse_header('Referer')
>     exnihilo> agent = cgi.parse_header('User-Agent')
> 
> They should be available in the environment as HTTP_USER_AGENT and
> HTTP_REFERER.  Take a look at
> 
>     http://www.musi-cal.com/cgi-bin/query
> 
> for an example.
> 
> Skip
> 

Thanks for the help. I tried using HTTP_USER_AGENT and HTTP_REFERER, but 
I get similar results, a tuple containing an empty dictionary.  Here is 
the output now:

Referer: ('http_referer', {})
User Agent: ('http_user_agent', {})

I also tried using just cgi.parse('HTTP_REFERER'), but that just refers 
an empty dictionary too.

thanks





More information about the Python-list mailing list