CGI: how to get referer header?

Skip Montanaro skip at
Sun Mar 23 00:15:16 CET 2003

    Skip> They should be available in the environment as HTTP_USER_AGENT and
    Skip> HTTP_REFERER.  Take a look at

    >> Thanks for the help. I tried using HTTP_USER_AGENT and HTTP_REFERER,
    >> but I get similar results, a tuple containing an empty dictionary.

Sorry, I should have given a specific example.  Try this:

    import os

    print "Referer:", os.environ.get("HTTP_REFERER", "<not present>")
    print "User Agent:", os.environ.get("HTTP_USER_AGENT", "<unknown>")


More information about the Python-list mailing list