Visit Our UNIX and Linux User Community

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

Thread Tools Search this Thread
Top Forums Web Development problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.
# 1  
Old 02-15-2012
Java 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 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...

Here is my first CGI script

#!/perl/bin/perl -wT
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/");
}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')),

Here is my second script:

#!/perl/bin/perl -wT
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();
# 2  
Old 02-15-2012
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
# 3  
Old 02-16-2012
Java POST aint working

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()
# 4  
Old 02-17-2012
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.

Last edited by DGPickett; 02-17-2012 at 01:14 PM..
This User Gave Thanks to DGPickett For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #292
Difficulty: Easy
In 2011, Google introduced the Chromebook, a web thin client running Android..
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Not able to copy the file in perl cgi script

Hello experts, I am facing an very typical problem and hope the issue can be solved. I have a page download.cgi in /cgi-bin folder. use CGI; use CGI::Carp qw ( fatalsToBrowser ); use File::Copy copy("C:\\Program Files\\Apache Software... (8 Replies)
Discussion started by: scriptscript
8 Replies

2. Shell Programming and Scripting

CGI Perl : while loop in CGI perl

Hi Team, I am trying to connect to database(succeeded ) and print the records on the browser using while loop. But the elements of array are not displayed instead while loop is displayed directly. Instead of the below I can embed html statements in print but I am looking for the below style as I... (1 Reply)
Discussion started by: scriptscript
1 Replies

3. Shell Programming and Scripting

Perl CGI : unable to download the excel sheet from perl cgi page

Hi All, I have written an cgi perl script that displays an image(Excel image) and when clicked on that Image I need to download a excel sheet. I made sure that excel sheet exists in the folder with the given name but still I am not able to download the sheet. print "<center><table... (2 Replies)
Discussion started by: scriptscript
2 Replies

4. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

5. Shell Programming and Scripting

Perl : embedding java script with cgi perl script

Hi All, I am aware that html tags can be embedded in cgi script as below.. In the same way is it possible to embed the below javascript in perl cgi script ?? print("<form action="action.htm" method="post" onSubmit="return submitForm(this.Submitbutton)">"); print("<input type = "text"... (1 Reply)
Discussion started by: scriptscript
1 Replies

6. Shell Programming and Scripting

Execution problem unix commands in Perl CGI

I am trying to run SSH , mkdir and other unix commands using Perl CGI. But i am not able to Execute these commands. Please help me out !!!! SSH and mkdir is necessity for me. I will be thankful to you...!!!!! I am trying like: In perl CGI file i am writing like: @list = `ssh... (28 Replies)
Discussion started by: Navrattan Bansa
28 Replies

7. Web Development

perl cgi script not working

Hello, Met a problem learning perl cgi script. 1 #!/usr/bin/perl -wT 2 3 use strict; 4 use CGI qw(:standard); 5 6 my $q = new CGI; 7 8 my $filename = $q->param('/home/yifangt/hello.cgi'); 9 my $contenttype = $q->uploadInfo($filename)->{'Content-Type'}; 10... (5 Replies)
Discussion started by: yifangt
5 Replies

8. Web Development

in cgi perl script a form

hi,i hav a form in cgi perl script.this script accepts a value from user from another html form, and depending upon this value,i need to disable /enable radio buttons in cgi-perl script wen second page is displayed on executing cgi perl do i do it using javascript? (0 Replies)
Discussion started by: raksha.s
0 Replies

9. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./ $t $d $m'); in shell scipt i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies

10. Web Development

Tool Tip on a Perl CGI script

Hi, I am writing a perl script using Perl CGI. There are various HTML tables and forms involved in this. Now I wanted to add a tool tip to the elements here but I am not able to find documentation on how to do it. Can anyone help? Thanks in advance. Regards, garric (5 Replies)
Discussion started by: garric
5 Replies

Featured Tech Videos