Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the CGI to determine which page loaded it

Status
Not open for further replies.

spyderco

Programmer
Jan 23, 2005
107
US
I have a CGI script which is being called from many different pages. I need the CGI script to determine which page just called it.

Say we are at . We are including the CGI script as an SSI. The CGI has to output the URL of page1.shtml.

Just for the sake of it, I also used
Code:
<!--#exec cgi="../cgi-bin/stats/downloads.pl"-->

My first idea was using $ENV{"HTTP_REFERER"}. I thought this worked at first but it turns out it only works if the page1.shtml is called directly. This is to say, if you are on and click a link to the CGI included on page1.shtml will say the referer was " and NOT page1.shtml which it should!

I have used both the SSI and the exec cgi code and using HTTP_REFERER but it's absolutely not working. Can someone tell me how I can get the URL of the page that called it?
 
The easiest and most reliable way would just be to pass a parameter to the script, like so:
Code:
<!--#include virtual="../cgi-bin/stats/downloads.pl?from=page1.shtml"-->
 
According to , there are environment variables called [tt]$ENV{'DOCUMENT_NAME'}[/tt] and [tt]$ENV{'DOCUMENT_URI'}[/tt] that hold the information you need.

If that doesn't work for you, try writing a little perl program that outputs the names and values of the whole %ENV hash. Call it as an SSI and see what's what!

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top