Passing info from one cgi to another

Anyone know how to pass some text from one cgi to another ?

I have a cgi which accepts a password from a form then opens another cgi which is another form but on a different server.

I want to keep that password "live" and insert it into a hidden field on the other server as part of a form.

The first (and easiest) that works gets 100 points ;-)
boneyAsked:
Who is Participating?
 
prakashk021799Connect With a Mentor Commented:
> I am going to accept prakashk's answer (if he proposes it) as it was the
> nearest to what actually worked !

Ok. I am posting it again as answer.


If you don't want the password to show up in the URL, then you would need to use the POST method to send the parameter values for the second script. You can use LWP::UserAgent module for this. In the second script read the values from STDIN (If you use CGI.pm, this part is automatically done for you).

Then script 1 would be some thing like:

       use LWP::UserAgent;
       use HTTP::Request::Common;

       $ua = new LWP::UserAgent;
       ## Assuming $password has the value you have already read from the user
       $ua->request(POST 'http://somewhere/script2.cgi', [ PASSWORD => $password]);
       # check the response etc.

In script 2:

       use CGI.pm qw(:standard);

       $password = param('PASSWORD');
0
 
prakashk021799Commented:
How do you invoke the second script?

You could save the password in an environment variable before invoking the second script.

Something like (in script 1):

$ENV{PASSWORD} = param('password');

# run the second cgi script here

In script 2:

# get the password
$password = $ENV{PASSWORD};

# get all the other CGI parameters

....


0
 
prakashk021799Commented:
Oops! Never mind.

I didn't look at the part where you said the second script is on a different server.
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
boneyAuthor Commented:
I was hoping I could do something simple like call the cgi and add ?field=something
0
 
prakashk021799Commented:
You could do that but the password would then be part of the URL for the second script. I thougth you wanted to avoid that. If that's not a problem you already got your solution.

If you don't want the password to show up in the URL, then you would need to use the POST method to send the parameter values for the second script. You can use LWP::UserAgent module for this. In the second script read the values from STDIN (If you use CGI.pm, this part is automatically done for you).

Then script 1 would be some thing like:

use LWP::UserAgent;
use HTTP::Request::Common;

$ua = new LWP::UserAgent;
## Assuming $password has the value you have already read from the user
$ua->request(POST 'http://somewhere/script2.cgi', [ PASSWORD => $password]);
# check the response etc.

In script 2:

use CGI.pm qw(:standard);

$password = param('PASSWORD');

0
 
boneyAuthor Commented:
Hmm

I do have those modules but I don't really call the script as such as it is just a url I load (I think )  :-)

the first script checks that the password is valid then chooses a url from a list to send them to which is then loaded but the url is hidden by the validate cgi...

does that help ?
0
 
helverCommented:
What you might be able to do is to construct an HTML frameset with only one
frame, that takes up the entire window.  Then, load the URL you want with the ?pass=passwd tacked onto the end.  

I think putting in a frame will sufficiently obscure the URL.

So essentially:

print "Content-type: text/html\n\n";
print "<html><head><title>Validated Page</title></head>";
print "<frameset cols="*"><frameset rows="*">";
print "<frame src="http://other.server.org/cgi.cgi?pass=passwd">";
print "</frameset></frameset></html>";
0
 
ozoCommented:
or <input type=hidden> like boney asked for
0
 
helverCommented:
Aw, damn...  I hope it wasn't really that simple...
0
 
tpryorCommented:
print("Location: http://www.somewhere.com/script2.cgi?pwd=$password");

this will redirect to another web page and pass the pwd var.
the other script must be set up to recieve this var in the usual way.

t
0
 
tpryorCommented:
oops forgot the newline charecters should be

print("Location: http://www.somewhere.com/script2.cgi?pwd=$password\n\n");
0
 
boneyAuthor Commented:
I am going to accept prakashk's answer (if he proposes it) as it was the nearest to what actually worked !

prakashk ?
0
 
boneyAuthor Commented:
Thanks guys !
0
All Courses

From novice to tech pro — start learning today.