Passing user data between scripts

G

game4itguy

Hi,

I'm positive this is very basic stuff, but I can't seem to find the
information I need, so if anyone could help I'd appreciate it. This is
what I'm trying to do as clearly as I can describe it...

1. I want a user to input data using the GET method.
2. I want 1.pl to display that data on a webpage.
3. I want a link at the bottom of 1.pl to 2.pl.
4. When the user clicks on the 2.pl link, I want 2.pl to display
exactly the same data as 1.pl.

This probably sounds pretty pointless, but I just want to have an
understanding of how it's done so I can use the concept in later
scripts.

I don't actually have a script written yet, but if one's required to
elicit a response, it would look something like the following off the
top of my head...

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;
my @userinfo = split(/&/, $ENV{'QUERY_STRING'});
my $data1 = $userinfo[0];
my $data2 = $userinfo[1];
print "Content-type: text/plain", "\n\n";
print "Welcome. $data1, $data2.<p>";
print q{<a href="2.pl">Click here for 2.pl</a>};
exit;

And if anyone feels the desire to also demonstrate how to do this with
the POST method instead of GET, I'd appreciate it!

Many thanks.
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g10g2000cwb.googlegroups.com:
1. I want a user to input data using the GET method.
2. I want 1.pl to display that data on a webpage.
3. I want a link at the bottom of 1.pl to 2.pl.
4. When the user clicks on the 2.pl link, I want 2.pl to display
exactly the same data as 1.pl.

This is a CGI question, not a Perl question.
I don't actually have a script written yet, but if one's required to
elicit a response, it would look something like the following off the
top of my head...

Please read the posting guidelines. In short, post real code.
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;
Excellent.

my @userinfo = split(/&/, $ENV{'QUERY_STRING'});
my $data1 = $userinfo[0];
my $data2 = $userinfo[1];

use CGI.pm;

Basically, don't parse the form by hand unless you are going to invest
the time to do it properly.
print "Content-type: text/plain", "\n\n";
print "Welcome. $data1, $data2.<p>";
print q{<a href="2.pl">Click here for 2.pl</a>};

Why lie about content type?
And if anyone feels the desire to also demonstrate how to do this with
the POST method instead of GET, I'd appreciate it!

For CGI specific questions, visit comp.infosystems.www.authoring.cgi

Read http://www.thinkspot.net/ciwac/howtopost.html before posting there.

Sinan
 
X

xhoster

Hi,

I'm positive this is very basic stuff, but I can't seem to find the
information I need, so if anyone could help I'd appreciate it. This is
what I'm trying to do as clearly as I can describe it...

1. I want a user to input data using the GET method.
2. I want 1.pl to display that data on a webpage.
3. I want a link at the bottom of 1.pl to 2.pl.
4. When the user clicks on the 2.pl link, I want 2.pl to display
exactly the same data as 1.pl.

This probably sounds pretty pointless, but I just want to have an
understanding of how it's done so I can use the concept in later
scripts.

I don't actually have a script written yet, but if one's required to
elicit a response, it would look something like the following off the
top of my head...

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;
my @userinfo = split(/&/, $ENV{'QUERY_STRING'});

You should almost certainly use CGI. Even more especially so as you are
already using CGI::Carp!
my $data1 = $userinfo[0];
my $data2 = $userinfo[1];
print "Content-type: text/plain", "\n\n";
print "Welcome. $data1, $data2.<p>";
print q{<a href="2.pl">Click here for 2.pl</a>};

Using CGI's functions, something like this (untested):

print q{<a href="2.pl?} . query_string() . q{">Click here for 2.pl</a>};

Althrough I rarely do this. If I want two different scripts to receive
pretty much the same data, I'd usually combine them into one script which
just took another paramter telling it whether you wanted mode1 behavior or
mode2 behavior.

Xho
 
G

game4itguy

Using CGI's functions, something like this (untested):
print q{<a href="2.pl?} . query_string() . q{">Click here for 2.pl</a>};

This is absolutely perfect for what I want to do (although I'm actually
passing along other variables using that format, not the query_string),
it works like a charm. Thanks for your help, it would have taken me
some time to have thought about doing it that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top