cgi script: get the url of this page

Peter van Kampen news at
Tue Aug 10 00:43:03 CEST 2004

In article <mailman.1409.1092077336.5135.python-list at>, Matt Price wrote:
> A super simple question:
> is there a standard trick to get the url of the current page in a cgi

import os

script = os.environ["SCRIPT_FILENAME"]

Look up the print_environ() function in the cgi-module for your python
version to give you an overview of available information.

> script, or the url from which form data has been passed??  I want to

Hmm. You can try HTTP_REFERER but it depends on several things (browser,
server, cgi-implementation etc.) wether this reports something useful or
not. It is probably more reliably to check REMOTE_ADDR if that would provide
enough information.



Peter van Kampen
pterk -- at --

More information about the Python-list mailing list