PERL CGI Script Responding to Link

D

Dr. Leff

I wrote a web site in Perl CGI. One of the familiar tasks in many
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 to
http://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"));
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>";
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";

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;
}
}

Any help would be greatly appreciated:

Dr. Laurence Leff Western Illinois University, Macomb IL 61455 ||
(309) 298-1315
Stipes 447 Assoc. Prof. of Computer Sci. Pager: 309-367-0787 FAX:
309-298-2302
 
J

Joost Diepenmaat

Dr. Leff said:
I wrote a web site in Perl CGI. One of the familiar tasks in many
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 to
http://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.


That's because parameters in the URL are not sent to a CGI script via
STDIN since they're not in the /body/ of the HTTP request. See the CGI specs.
RFC 3875, section 4.1.7 in particular.

In general, though, you're /much/ better off using the standard CGI
module since it automatically handles this issue and much more.

http://perldoc.perl.org/CGI.html

HTH,
Joost.
 
L

Lars Eighner

In our last episode,
the lovely and talented Dr. Leff
broadcast on comp.lang.perl.misc:
I wrote a web site in Perl CGI. One of the familiar tasks in many 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.

So, you suppose a mailreader is a web browser? Why would you do that?
 
R

Ron Bergin

I wrote a web site in Perl CGI. One of the familiar tasks in many
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"));
You should always check the return value of an open call. Nowdays
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";
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;
}

}
No need to manually do that yourself, and as you've discovered it's
easy to do it incorrectly and not get the desired results. Use the
CGI module!
 
P

Peter J. Holzer

In our last episode,
the lovely and talented Dr. Leff
broadcast on comp.lang.perl.misc:


So, you suppose a mailreader is a web browser?

No, he doesn't. He merely supposes that the user receiving the mail is
able to invoke a web browser. Since that person just tried to register
themselves at a web site, this is not an unreasonable assumption.

hp
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top