CGI: how to get referer header?

Skip Montanaro skip at pobox.com
Sat Mar 22 10:43:32 EST 2003


    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





More information about the Python-list mailing list