problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect.
Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is
redirected to welcome page.

My requirement is, the welcome page should display the username. "Hello, admin"

Note: I dont want to use cookies.

Any help is highly appreciated...

Thanks in advance...
-Arun

Here is my first CGI script login.pl:

#!/perl/bin/perl -wT
#login.pl
use warnings;
use CGI::Pretty qw(:all);
use strict;
my $cgi=new CGI;
my $username=$cgi->param('username');
my $password=$cgi->param('password');
my $db_username="admin";
my $db_password="admin";
if ( $username eq $db_username && $password eq $db_password ) {
print $cgi->redirect("http://localhost/welcome.pl");
}else {
print header();
print start_html(-title=>"Login");
if ($cgi->param('username') or $cgi->param('password')) {
print center(font({-color=>'red'},"Invalid input"));
}
print generate_form();
print end_html();
}

sub generate_form {
return start_form,
h1("Please Login"),
p("username", textfield('username')),
p("password", textfield('password')),
p(submit),
end_form;
}

Here is my second script:

#!/perl/bin/perl -wT
#welcome.pl
use warnings;
use CGI::Pretty qw(:all);
use strict;
my $cgi=new CGI;
my $username;
print header();
print start_html("Welcome"),h1("Hello, $username");
print end_html();

Older than cookies are hidden form variables for the form processing second cgi (remaining hidden from the user if POST), or forming a URL to redirect to with GET url-encoded parameters: http://mysvr/cgi-bin/cgi2?x=1&y=2

sending URL with parameters works fine, but this reveals the parameters sent.. I want to hide it.. probably POST will the best one.. but how does a CGI script send POST to another CGI script ?
it will be really helpful if you could send me the syntax. I'm using "CGI::Pretty".

I tried sending POST using param(). But i wonder how to add param() in redirect()

It is simplest if the first CGI generates a FORM that POST's with HIDDEN variables to the second CGI. (BTW, put the HIDDEN variables right after FORM so they are not dropped. I made an HTML page where the SUBMIT was early, the middle processing was slow and the HIDDEN were at the bitter end of the FORM, and if the SUBMIT was hit immediately when it appeared, the HIDDEN were not honored. Probably a bug, but be aware.)

If you want to redirect to a POST CGI, you probably cannot pass FORM variables when you use the HTML META redirect, but you can call it yourself (your service acting like a browser/client and connecting to the server of the second CGI) and pass the appropriate encoded variables after the HTTP header and pass all or part of the content from the response to send to the browser as the whole response or as part of your response page. In most cases, you can use URL-encoding, but not always. For instance, file uploads must use POST with MIME encoding.

BTW, I am not a PERL web guy, just an HTTP/HTML hacker, but it is best to know what the PERL is doing for you. It has nice libraries, but they are just code that reads and writes bytes of HTTP and often HTML through a web server to a socket to the browser. The web server just passes the header and socket info in the environment and socket to stdin CGI input, and checks your return status before putting of the first line of the HTTP header out and sending your stdout response.

1 Like