For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > November 2005 > Redirect and pass variables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Redirect and pass variables
Ed Jay

2005-11-14, 9:56 pm

I have a multi-file script (Not cgi). I read in variables from an
HTML-based form, add values for a few more variables using a form, and
then submit the new values plus the original values, in hidden form
fields, to the next Perl script.

If a couple of variables have zero value, I want to skip processing on the
'next' page and redirect to page2n. I'm using the following simple logic
and redirect in Page n's script:

Read in previous variables.

if ($var1 + var2 == 0) {print 'Status: 302 Moved', "\r\n", 'Location:
/cgi-bin/pagen2.cgi', "\r\n\r\n";}

Problem is, the values for all previous variable do not pass to page2n.

How do I solve this issue?

--
Ed Jay (remove M to respond by email)
Gunnar Hjalmarsson

2005-11-14, 9:56 pm

Ed Jay wrote:
> I have a multi-file script (Not cgi).


???

> I read in variables from an
> HTML-based form, add values for a few more variables using a form, and
> then submit the new values plus the original values, in hidden form
> fields, to the next Perl script.
>
> If a couple of variables have zero value, I want to skip processing on the
> 'next' page and redirect to page2n. I'm using the following simple logic
> and redirect in Page n's script:
>
> Read in previous variables.
>
> if ($var1 + var2 == 0) {print 'Status: 302 Moved', "\r\n", 'Location:
> /cgi-bin/pagen2.cgi', "\r\n\r\n";}
>
> Problem is, the values for all previous variable do not pass to page2n.
>
> How do I solve this issue?


perldoc HTTP::Request::Common

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Matt Garrish

2005-11-14, 9:56 pm


"Ed Jay" <edMbj@aes-intl.com> wrote in message
news:4mein1hrgppkcd63kqnehbort15tn7r1f1@
4ax.com...
>I have a multi-file script (Not cgi). I read in variables from an
> HTML-based form, add values for a few more variables using a form, and
> then submit the new values plus the original values, in hidden form
> fields, to the next Perl script.
>
> If a couple of variables have zero value, I want to skip processing on the
> 'next' page and redirect to page2n. I'm using the following simple logic
> and redirect in Page n's script:
>
> Read in previous variables.
>
> if ($var1 + var2 == 0) {print 'Status: 302 Moved', "\r\n", 'Location:
> /cgi-bin/pagen2.cgi', "\r\n\r\n";}
>


Please don't retype code. It makes it difficult to know what you're real
problem is (var2 should be $var2 above, one would assume). Also, it's
strange that they aren't cgi scripts, but they have cgi extensions and use
the gateway...

> Problem is, the values for all previous variable do not pass to page2n.


Because you didn't pass them. All you did was redirect:

print "Location: /cgi-bin/pagen2.cgi?var1=$var1&var2=$var2\n\n";

Of course, you may want to consider uri escaping the variables before
including them in the string, but that's left as an exercise for you...

Matt



Ed Jay

2005-11-14, 9:56 pm

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote:

>
>"Ed Jay" <edMbj@aes-intl.com> wrote in message
> news:4mein1hrgppkcd63kqnehbort15tn7r1f1@
4ax.com...
>
>Please don't retype code. It makes it difficult to know what you're real
>problem is (var2 should be $var2 above, one would assume).


Sorry $var2.

>Also, it's
>strange that they aren't cgi scripts, but they have cgi extensions and use
>the gateway...


The scripts are written in Perl, but I don't use the CGI module.
>
>
>Because you didn't pass them. All you did was redirect:
>
>print "Location: /cgi-bin/pagen2.cgi?var1=$var1&var2=$var2\n\n";
>
>Of course, you may want to consider uri escaping the variables before
>including them in the string, but that's left as an exercise for you...
>

Thanks, Matt.

--
Ed Jay (remove M to respond by email)
Ed Jay

2005-11-15, 7:55 am

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote:

>
>"Ed Jay" <edMbj@aes-intl.com> wrote in message
> news:4mein1hrgppkcd63kqnehbort15tn7r1f1@
4ax.com...
>
>Please don't retype code. It makes it difficult to know what you're real
>problem is (var2 should be $var2 above, one would assume). Also, it's
>strange that they aren't cgi scripts, but they have cgi extensions and use
>the gateway...
>
>
>Because you didn't pass them. All you did was redirect:
>
>print "Location: /cgi-bin/pagen2.cgi?var1=$var1&var2=$var2\n\n";
>
>Of course, you may want to consider uri escaping the variables before
>including them in the string, but that's left as an exercise for you...
>

Pardon me for retyping the code, but I have no idea how else to say that:

print "Location:...
/url.cgi?\$patient_id=\$patient_id&\$exam_date=\$exam_date&\$refer_clinic=\$refer_clinic\n\n";

isn't working.

After it redirects I see the url, inclusive of the ? and everything after
it in the browser's address bar, but the variables don't get passed.

--
Ed Jay (remove M to respond by email)
Ed Jay

2005-11-15, 7:55 am

Ed Jay <edMbj@aes-intl.com> wrote:

>"Matt Garrish" <matthew.garrish@sympatico.ca> wrote:
>
>Pardon me for retyping the code, but I have no idea how else to say that:
>
>print "Location:...
>/url.cgi?\$patient_id=\$patient_id&\$exam_date=\$exam_date&\$refer_clinic=\$refer_clinic\n\n";
>
>isn't working.
>
>After it redirects I see the url, inclusive of the ? and everything after
>it in the browser's address bar, but the variables don't get passed.


To follow up...

I've renamed my scripts with the extension 'pl.'
My redirect precedes the document type header.
I've tried:

..pl?var1=var1
..pl?var1=$var1
..pl?var1=\$var1
..pl?$var1=$var1
..pl?\$var1=\$var1
..pl?var1=$formdata{'$var1'}
..pl?var1=\$formdata{'$var1'}

all to no avail.

--
Ed Jay (remove M to respond by email)
Matt Garrish

2005-11-15, 7:55 am


"Ed Jay" <edMbj@aes-intl.com> wrote in message
news:5q9jn1lng6u86patiu4glq0n4urj53e4lg@
4ax.com...
> Ed Jay <edMbj@aes-intl.com> wrote:
>
>
> To follow up...
>
> I've renamed my scripts with the extension 'pl.'
> My redirect precedes the document type header.
> I've tried:
>
> .pl?var1=var1
> .pl?var1=$var1
> .pl?var1=\$var1
> .pl?$var1=$var1
> .pl?\$var1=\$var1
> .pl?var1=$formdata{'$var1'}
> .pl?var1=\$formdata{'$var1'}
>
> all to no avail.


Which begs the question, if you're not using CGI.pm, how are you accessing
the variables? If you're using code that only processes post requests, then
it's not surprising that nothing turns up in your second script. Without
seeing the code you're using to get the variables, however, there's no way
of helping you at this point.

Matt


Ed Jay

2005-11-15, 9:55 pm

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote:

>
>"Ed Jay" <edMbj@aes-intl.com> wrote in message
> news:5q9jn1lng6u86patiu4glq0n4urj53e4lg@
4ax.com...
>
>Which begs the question, if you're not using CGI.pm, how are you accessing
>the variables? If you're using code that only processes post requests, then
>it's not surprising that nothing turns up in your second script. Without
>seeing the code you're using to get the variables, however, there's no way
>of helping you at this point.
>

Here is the code to access the variables, followed by three of the 60
variables I'm trying to pass:

$buffer = "";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair (@pairs)
{
@a = split(/=/,$pair);
$name=$a[0];
$value=$a[1];
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$value =~ s/\+/ /g;
$value =~ s/\r//g;
push (@data,$name);
push (@data, $value);
}
%formdata=@data;
%formdata;

$var1 = $formdata{'var1'};
$var2 = $formdata{'var2'};
$var3 = $formdata{'var3'};

--
Ed Jay (remove M to respond by email)
Matt Garrish

2005-11-15, 9:55 pm


"Ed Jay" <edMbj@aes-intl.com> wrote in message
news:m3ujn1t48j4uh2c0cu61ehfliclut0p8e1@
4ax.com...
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote:
>
> Here is the code to access the variables, followed by three of the 60
> variables I'm trying to pass:
>
> $buffer = "";
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});


You're not posting the data on the redirect, so you have to read the query
string instead. I would recommend using CGI.pm, but if you're determined to
stay with what you have you're going to have to start checking how your data
is arriving and process it accordingly.

Matt


Ed Jay

2005-11-15, 9:55 pm

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote:

>
>"Ed Jay" <edMbj@aes-intl.com> wrote in message
> news:m3ujn1t48j4uh2c0cu61ehfliclut0p8e1@
4ax.com...
>
>You're not posting the data on the redirect, so you have to read the query
>string instead. I would recommend using CGI.pm, but if you're determined to
>stay with what you have you're going to have to start checking how your data
>is arriving and process it accordingly.
>

Matt, I think you hit the nail on the head about the same time as I was
led to. I'm reading the form data as standard (Post), but redirecting via
the URL, which is submitting via Get.
>

That I'm seeing the correct string in the browser addy field tells me the
data is being sent properly....at least the way it's being told.

--
Ed Jay (remove M to respond by email)
Joe Smith

2005-11-18, 6:57 pm

Ed Jay wrote:

> The scripts are written in Perl, but I don't use the CGI module.


A script is considered to be a "CGI script" if it executed by
a web server's Common Gateway Interface. The lack of "use CGI;"
does not change this.
-Joe
Joe Smith

2005-11-18, 6:57 pm

Ed Jay wrote:

>
> Pardon me for retyping the code, but I have no idea how else to say that:
>
> print "Location:...
> /url.cgi?\$patient_id=\$patient_id&\$exam_date=\$exam_date&\$refer_clinic=\$refer_clinic\n\n";
>
> isn't working.


There, you've done it again. (Three periods after "Location:", indeed.)
You should copy-and-paste the actual code, not re-type it.

-Joe
Ed Jay

2005-11-22, 3:56 am

Joe Smith <joe@inwap.com> wrote:

>Ed Jay wrote:
>
>
>A script is considered to be a "CGI script" if it executed by
>a web server's Common Gateway Interface. The lack of "use CGI;"
>does not change this.
> -Joe


Doesn't "use CGI" tell Perl to load the CGI.pm module which it otherwise
wouldn't do?

--
Ed Jay (remove M to respond by email)
Paul Lalli

2005-11-22, 3:56 am

Ed Jay wrote:
> Joe Smith <joe@inwap.com> wrote:
>
>
> Doesn't "use CGI" tell Perl to load the CGI.pm module which it otherwise
> wouldn't do?


Yes. And...? What are you actually trying to ask?

CGI.pm is simply a module that provides an easy-to-use interface to the
Common Gateway Interface. There's no reason at all you can't use CGI
without `use CGI;`. (This is PurlGurl's cue to come into the
conversation, by the way. . . )

Paul Lalli

Ed Jay

2005-11-22, 3:56 am

"Paul Lalli" <mritty@gmail.com> wrote:

>Ed Jay wrote:
>
>Yes. And...? What are you actually trying to ask?
>
>CGI.pm is simply a module that provides an easy-to-use interface to the
>Common Gateway Interface. There's no reason at all you can't use CGI
>without `use CGI;`. (This is PurlGurl's cue to come into the
>conversation, by the way. . . )
>

Thanks, Paul. I understand. I got the impression from Joe's comment that
regardless of whether or not one uses "Use CGI" that Perl would still use
the module.

--
Ed Jay (remove M to respond by email)
Joe Smith

2005-11-24, 7:56 am

Ed Jay wrote:
> Joe Smith <joe@inwap.com> wrote:
>
>
>
>
> Doesn't "use CGI" tell Perl to load the CGI.pm module which it otherwise
> wouldn't do?


True but irrelevant. A "CGI script" can be written in FORTRAN,
in the Bourne shell, in TCL, and even in COBOL. None of those
use CGI.pm but they are CGI programs because they were designed
to operate in the Common Gateway Interface (CGI) environment.
-Joe
Sherm Pendley

2005-11-24, 7:56 am

Joe Smith <joe@inwap.com> writes:

> True but irrelevant. A "CGI script" can be written in FORTRAN,
> in the Bourne shell, in TCL, and even in COBOL. None of those
> use CGI.pm but they are CGI programs because they were designed
> to operate in the Common Gateway Interface (CGI) environment.


The converse is also true, BTW. A Perl script that uses CGI.pm can be
run from a command-line for debugging, or under mod_perl. In neither
case is it running in a CGI environment.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com