Forum Moderators: phranque
Details:
-------
The problem is, I want to set a variable with a perl script, redirect the page elsewhere and have the variable be able to be picked up at the other end.
Obviously environment variables are only for that sessions so setting an environment variable doesn't work.
You would think that the apache "PassEnv" command would be specifically for this, but I tried this and it doesn't work after I set an environment variable in perl (those not fluent in perl just take my word for it, this should work and doesn't:
------ start.cgi -----
#!/usr/bin/perl
use CGI;
$ENV{'myvar'} = 'hello world!';
print CGI->redirect('end.cgi');
exit; ------ .htaccess -----
PassEnv myvar ------ end.cgi -------
#!/usr/bin/perl
use CGI;
print CGI->header();
if($ENV{'myvar'}) {print "success!";}
else {print "failure :(";}
exit; Running start.cgi in a browser produces "failure :(".
So the other idea I had was to send it in the header, and then retrieve it from the header at the other end:
----- start.cgi -----
#!/usr/bin/perl
use CGI;
print CGI->redirect(
-uri=>'end.cgi',
-myvar=>'hello world!'
);
exit; ------ .htaccess ----
# I was hoping I could somehow use SetEnv to set the variable from the http header
SetEnv myvar #*$!xx end.cgi would be the same.
Please let me know if you can help.
Thanks.
Robin.
[edited by: theRatWonder at 9:26 pm (utc) on April 15, 2007]
----- start.cgi ----
#!/usr/bin/perl
use CGI;
$ENV{'myvar'} = 'hello world!';
print CGI->header();
print `perl end.cgi`;
exit; ----- end.cgi ------
#!/usr/bin/perl
if($ENV{'myvar'}) {print "success!<br />" . $ENV{'myvar'};}
else {print "failure :(";}
exit; Running start.cgi in a browser prints out:
Success!
hello world! [edited by: theRatWonder at 9:26 pm (utc) on April 15, 2007]
So, either set the cookie response header with a valid cookie containing the data you want to pass, or bolt the data onto the redirect-to URL as in "Location: [exmple.com...]
Jim