Re: PERL CGI Script Responding to Link
- From: Ron Bergin <rkb@xxxxxxxxxx>
- Date: Sat, 29 Dec 2007 12:18:49 -0800 (PST)
On Dec 29, 8:44 am, "Dr. Leff" <mf...@xxxxxxx> wrote:
I wrote a web site in Perl CGI. One of the familiar tasks in manyYou should always check the return value of an open call. Nowdays
web sites
is validating new users. Traditionally, they enter their email,
desired login
and password. The system sends a confirmation email with a link on
which
to click. The user checks their email, clicks and the system knows
they
are a "real" person.
My web systems send a message like this after the user enters their
desired
login, email address and the demographic information we want:
I aped the format used when one clicks
the submit button on a form.
<A href="http://www.wiu.edu/users/mflll/2/confirm.scgi?C=tic5any&L=c">
Please click here to confirm your login or go tohttp://www.wiu.edu/users/mflll/2/confirm.scgi?C=tic5any&L=c</A>
__________________________________________________________________________
But, when I click on it, it calls confirm.scgi as we expect.
Unfortunately, the parameters are not
passed in the standard input.
The beginning of the script, confirm.scgi is instrumented for
debugging
as follows.
Observe that there is no data in STDIN.
#!/usr/local/bin/perl
require "/home/mflll/http/2/ll.pm";
use IO::Handle;
open (out,">".ll::FN("debugconfirm.out"));
it's preferable to use the 3 arg form of open and a lexical var for
the filehandle.
open (my $out, '>', ll::FN("debugconfirm.out") ) or die $!;
out->autoflush(1);$out->autoflush(1);
print "Content-type: text/html\n\n";
print "<HTML>";
print "$ENV{'BASE'}<HEAD>";
print "<TITLE>Confirm Login </TITLE>";
print "</HEAD>";
print "<BODY>";
Why the multiple pront statements?
What is in $ENV{'BASE'} and does it need to be in the head section?
The use of the CGI module could simplify this.
use CGI;
my $cgi = CGI->new; # I prefer the OO style instead of the
functional.
my %vars = $cgi->Vars; # fetch the params and place them in a hash.
print $cgi->header, # If needed, $ENV{'BASE'} could be added
$cgi->start_html('Confirm Login');
print out "in confirm\n";
## get the login id and Confirmation Code, which should be in the CGI
## query string
print out "standard input |".<STDIN>."|\n";
print $out "standard input | $vars{'C'} |\n";
No need to manually do that yourself, and as you've discovered it's
The output is as follows:
in confirm
standard input ||
Normally, when I read information from a form in a perl CGI script, I
use
a loop to read the standard information. This does matches against
the
parameter names to extract the contents. When I tried this (see code
below),
I got no information -- and debugging showed that it did not enter the
loop.
while (<STDIN>) {
print out "confirming standard input |".$_."|\n";
if (/LoginID=([^&]+)/) {
$login = $1;
}
if (/C=([^&]+)/) {
$Code = $1;
}
}
easy to do it incorrectly and not get the desired results. Use the
CGI module!
.
- References:
- PERL CGI Script Responding to Link
- From: Dr. Leff
- PERL CGI Script Responding to Link
- Prev by Date: Re: Problem about type glob reference
- Next by Date: Re: compare 2 data files and extract fields for matched lines
- Previous by thread: Re: PERL CGI Script Responding to Link
- Next by thread: FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS?
- Index(es):