cgi script: get the url of this page

M

Matt Price

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
 
P

Peter van Kampen

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
 
M

Matt Price

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!
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,216
Latest member
DarrelLho

Latest Threads

Top