Here are both auth scripts in their entirety. As you can see I'm trying to pass a param from one script to the other by saving it locally as a cookie. The user's SSN is saved as a cookie and he is redirected after authenticaion.
One question I have is this:
If I pass a param from one script to another as part of the URL (querystring) is there any way to retrieve and store it in the second script as a scalar:
http://
www.mysite.com/test.pl?value=junk And then in test.pl:
my Value = param("value");
I realize the above won't work as value isn't actually a form. I'm just wondering if there's something similar to ASP's Request.Querystring?
The "print cookie" part of the second script returns nothing.
Any help (including a new way of performing what I need to) would be greatly appreciated!
SCRIPT 1
#!/usr/bin/perl -w
## html headers
print "Content-type: text/html\n\n";
print "<head><title>Verifying login</title>";
## mods
use DBI;
use CGI qw(param);
## connect to the database
my $dbh = DBI->connect( "dbi:mysql:maindata", "","" );
my $ssn = param("username");
my $password = param("password");
## prepare a SQL statement for execution
$sth = $dbh->prepare( "SELECT * FROM users where ssn Like '$ssn'");
## execute the statement in the database
$sth->execute();
## retrieve the returned rows of data
@row = $sth->fetchrow_array();
my $admin = @row[1];
my $loggedin = @row[3];
## check pass
if ($password ne $row[0]) {
print "Username and/or password incorrect. Please go back and try again.";
die("Username and password do not match. Please click back and reenter.");
}
if ($password eq $row[0]) { &Checkaccess; }
else { print "<META http-equiv=\"refresh\" content=\"0; URL=http://snoopy.edtech/p.stewart/va/student.html\">"; }
sub Checkaccess() {
if ($loggedin ne "1") {
$sth2 = $dbh->prepare("DELETE FROM users where ssn Like '$ssn'");
$sth2->execute();
if ($type eq "student") {
$admin = 3;
}
if ($type eq "faculty") {
$admin = 2;
}
$query2 = "INSERT INTO users (password, admin, ssn, loggedin)
VALUES ('$password', '$admin', '$ssn', '1')";
$sth3 = $dbh->prepare($query2);
$sth3->execute();
#Print change password form
print qq {
<html>
<form method="post" action="/cgi-bin/p.stewart/changepass.pl">
Choose a new password: <input type="password" name="password"><br><br>
<input type=hidden name=ssn value="$ssn">
<input type=hidden name=admin value="$admin">
<input type=submit>
</form>
</html>
}
} else {
print "Content-type: text/html\n\n";
"Set-Cookie: SS=deleted; expires=Thu, 01-Jan-1970 00:00:00 GMT;\n";
my $INN = new CGI;
# Define the cookie.
my $cookie = $INN->cookie( -name=> 'SS', -value => $ssn, expires => '+24h', domain => '' );
# Create the cookie.
print $INN->header(-cookie=>[$cookie]);
if ($row[1] eq "1") {
print "<META http-equiv=\"refresh\" content=\"0; URL=http://snoopy.edtech./p.stewart/va/admin.html\">";
}
elsif ($row[1] eq "2") {
print "<META http-equiv=\"refresh\" content=\"0; URL=http://snoopy.edtech/p.stewart/va/faculty.html\">";
}
elsif ($row[1] eq "3") {
print "<META http-equiv=\"refresh\" content=\"0; URL=http://snoopy.edtech./cgi-bin/p.stewart/student.pl">";
}
}
} SCRIPT 2
#!/usr/bin/perl -w
# mods
use CGI qw(param);
use CGI::Cookie;
## html headers
print "Content-type: text/html\n\n";
my $INN = new CGI;
# Fetch and print cookie.
my $idd = $INN->cookie('SS');
print "Test: $idd" || die("no");
Thanks again! Paul