Click to See Complete Forum and Search --> : [RESOLVED] Redirecting with environment variables


theRatWonder
04-15-2007, 11:57 AM
Heya.

Is it possible to redirect to a new page but by setting the HTTP headers or maybe something within the apache server I could pass Environment Variables along with it?

For almost all the pages on my site I use no CGI but only html pages with Apache SSI tags to include headers etc.

I have one page that needs to be passed variables from a CGI script, but so I don't have to rewrite the HTML page it would be best if I could leave the server parsing it. Redirecting would see the obvious answer:

my $cgi = new CGI;
print $cgi->redirect('http://mysite.com/page.html');

Cos then the server would parse it, but I need to pass an environment variable somehow so that page.html could pick it up with <!--#echo var="VARNAME" -->.

I tried print $cgi->(-uri=>'http://mysite.com/page.html',-VARNAME=>'hello' but that doesn't work.

Any suggestions?

theRatWonder
04-15-2007, 04:46 PM
Hmmm this forum seems rather dead

Nedals
04-15-2007, 08:32 PM
print "Location:/page.html\n\n";

The "\n\n" is required.

theRatWonder
04-15-2007, 08:34 PM
Thanks for trying to help, but did you actually read the question? What you've provided simply redirects a page. I can do that already.

Jeff Mott
04-15-2007, 09:13 PM
Probably your best option is to use the HTML::Template (http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm) module. You won't need to redirect and you won't need to write the page.

theRatWonder
04-17-2007, 07:21 AM
I solved this on my PC's server by using the CGI::SSI module, but then CGI::SSI wasn't installed on my live server, so that was out the window. I ended up using an iframe to load the CGI script within an SHTML page.

Jeff Mott
04-17-2007, 09:55 AM
. . . but then CGI::SSI wasn't installed on my live server, so that was out the window.A Perl module is (usually) nothing more than Perl code in a text file with a PM extension. You could copy module into the directory with your script and upload both to the server.

Nedals
04-17-2007, 12:23 PM
Here is another approach you could consider using a little javascript. This method could work if only a small amount of data is parsed.

Going back to my earlier post (where I did not read the question :) )

print "Location:/page.html?var=hello\n\n";
Now use javascript's 'location.search' and innerHTML functions to display 'var' within the HTML page.

theRatWonder
04-19-2007, 01:26 AM
Yeah, it would work, but the whole point of this exercise was to provide a non-javascript alternative to an application that normally runs completely with javascript Ajax.

theRatWonder
04-19-2007, 01:28 AM
Oh and by the way, the admins on my server installed CGI::SSI as soon as I asked, so I didn't need to bother with the other solutions. It now works a treat. (although I did find it a bit annoying that CGI::SSI doesn't understand <!--#set--> or properly parse a lot of <!--#if--> tags.)

But thanks for the PM tip Jeff, although I guess if I really think about it I knew that, I would never have thought of it. Thanks, that may well come in handy in future.

Robin.