470,604 Members | 2,226 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

cgi script: get the url of this page

A super simple question:

is there a standard trick to get the url of the current page in a cgi
script, or the url from which form data has been passed?? I want to
embed the name of the current page in a form field for two reasons:
(1) sometimes I want to send form data to the current page;
(2) sometimes I want to know where the daa came from, so I can add
that information to a database.

thanks again,

Matt
-------------------------------------------
Matt Price ma********@utoronto.ca
History Department, University of Toronto
(416) 978-2094
--------------------------------------------
Jul 18 '05 #1
2 7075
In article <ma**************************************@python.o rg>, 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.

Hth,

PterK

--
Peter van Kampen
pterk -- at -- datatailors.com
Jul 18 '05 #2
On Tue, Aug 10, 2004 at 12:43:03AM +0200, Peter van Kampen wrote:
is there a standard trick to get the url of the current page in a cgi
import os

script = os.environ["SCRIPT_FILENAME"]

great, thanks for the hint. tho I think "script_filename" gives the
file name, not the internet url -- for that REQUEST_URI seems to be
better. This is great, thanks!
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.

hmm, REMOTE_ADDR doesn't seem to show up mosto f the time;
HTTP_REFERRER works great, though, long as the fom isn't sent to the
page it came from...

thanks much!
matt

Hth,

PterK


-------------------------------------------
Matt Price ma********@utoronto.ca
History Department, University of Toronto
(416) 978-2094
--------------------------------------------
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by bhennon | last post: by
6 posts views Thread by Mike Daniel | last post: by
4 posts views Thread by Christopher Benson-Manica | last post: by
1 post views Thread by ebrandmark | last post: by
4 posts views Thread by Russ | last post: by
12 posts views Thread by Marc | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.