Perl, POST, and Redirect, CGI.pm

M

Michael

I have a problem. I have a cgi script which prints a form on the
screen. When the users clicks submit, it posts back to itself to
validate the form fields. If all the form's data is valid, it uses
the redirect method of CGI.pm to go to another cgi script. If the
form data is all valid, the first script dumps that data into a file
it creates on the server, then redirects to the second script. Then
the second cgi script opens up that file and retrieves the data from
it and uses it. Here's the Problem: apparently the server's
permissions have been changed, and scripts are no longer permitted to
create files on it. I can't change the permissions (client's rules).

This whole complicated system is simply to get the validated data from
the first script to the second without having it show in the URL, for
privacy reasons. Is there any way to use the redirect method in Perl
in such a way that it posts data - either from the form, or that I
give it as parameters? Is there another approach besides the redirect
method I might use? This system used to work until the client made a
bunch of changes to the server.

Thanks,
Michael
 
G

Gunnar Hjalmarsson

Michael said:
This whole complicated system is simply to get the validated data
from the first script to the second without having it show in the
URL, for privacy reasons. Is there any way to use the redirect
method in Perl in such a way that it posts data - either from the
form, or that I give it as parameters?

Don't know. Probably not.
Is there another approach besides the redirect method I might use?

You can use HTTP::Request::Common to make a POST request.

But if the other script is on the same server, can't you just
incorporate in via e.g. the require() function?
 
D

David K. Wall

Don't know. Probably not.


You can use HTTP::Request::Common to make a POST request.

But if the other script is on the same server, can't you just
incorporate in via e.g. the require() function?

I wonder why they are two separate programs in the first place? It
would be simpler (to me, anyway), to do something like this:

If the program is called without parameters, it returns a form and
references itself in the form action, using the POST method. Program
takes POSTed data, checks for validity. If data is invalid, return an
error message to the browser and exit. If the data is valid, continue
processing. Standard CGI practice, regardless of the language being
used.
 
A

Alan J. Flavell

If the program is called without parameters, it returns a form and
references itself in the form action, using the POST method. Program
takes POSTed data, checks for validity. If data is invalid, return an
error message to the browser and exit.

More politely, rebuild a copy of the form with the good data
pre-entered and the bad data highlighted, and exit.

None of that part of the problem is Perl-specific (translation: it's
mostly off-topic here and would be better dealt with on a CGI-specific
group), but my page
http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html might just
contain something useful (see the Perl sample right at the end).

good luck
 
J

Joe Smith

Michael said:
If all the form's data is valid, it uses
the redirect method of CGI.pm to go to another cgi script.

The other option is to have the first CGI script do a POST to
the second on, wait for the results to come back, then send
the results to the browser. You will need to convert
relative URLs in the returned data.
-Joe
 
M

Michael, TransmissionsLLC

Thanks for the tip, Gunnar. The problem, it turns out, was that someone
else had changed the structure of the server without informing everyone of
the changes. I will keep your recommendation in mind as I am sure I will
come across a problem that requires it in the future.

Michael
 
C

Chris

Michael said:
I have a problem. I have a cgi script which prints a form on the
screen. When the users clicks submit, it posts back to itself to
validate the form fields. If all the form's data is valid, it uses
the redirect method of CGI.pm to go to another cgi script. If the
form data is all valid, the first script dumps that data into a file
it creates on the server, then redirects to the second script. Then
the second cgi script opens up that file and retrieves the data from
it and uses it. Here's the Problem: apparently the server's
permissions have been changed, and scripts are no longer permitted to
create files on it. I can't change the permissions (client's rules).

This whole complicated system is simply to get the validated data from
the first script to the second without having it show in the URL, for
privacy reasons. Is there any way to use the redirect method in Perl
in such a way that it posts data - either from the form, or that I
give it as parameters? Is there another approach besides the redirect
method I might use? This system used to work until the client made a
bunch of changes to the server.

The better way has already been presented to you by David Wall -- when
the form is POSTed, check for validity and keep processing. Why add all
that overhead with I/O to disk, re-opening the file, re-parsing it...?
My goodness...!

If you just HAVE to do it that way and your second script is modified to
receive data via CGI.pm, then you don't need POSTed data -- use a GET
URL in your CGI redirect:

my $q = new CGI;
$q->redirect( "/cgi-bin/second-script.pl?var1=foo&var2=bar" );

You have to build the GET URL string though.

-ceo
 
G

Gunnar Hjalmarsson

Thanks for the tip, Gunnar. The problem, it turns out, was that
someone else had changed the structure of the server without
informing everyone of the changes.

Suggest your client to change hosting provider.
 
G

Gunnar Hjalmarsson

If you just HAVE to do it that way and your second script is
modified to receive data via CGI.pm, then you don't need POSTed
data -- use a GET URL in your CGI redirect:

??
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top