in reply to HTML::Template and setting Cookies
sub Login
{
# Local variables
my $self = shift;
my $cgi = $self->query();
my $permissions = "";
my $template;
# Check the database for the username and password
my $dbh = DBI->connect("DBI:mysql:$databaseName", $dbUser, $dbPass) or die "Could not connect to database: " . DBI->errstr;
my $sth = $dbh->prepare('SELECT Users.permissions FROM Users WHERE username=? AND password=?');
$sth->execute($cgi->param('username'), $cgi->param('password')) or die DBI->errstr;
# see if the user was in the database
if (my @permissions = $sth->fetchrow_array)
{
# They have a valid login. Get the template
$template = $self->load_tmpl("loginVALID.html");
# Make a cookie
my $cookie = $cgi->cookie(-name => 'browserID',
-value => '55',
-expires => '+30m',
-domain => 'dshack.com');
# Give the cookie to the browser
$self->header_props(-cookie => $cookie);
# Set the redirect
$template->param('redirect',cgi->param("redirect"));
}
else
{
# they do not have a valid login
$template = $self->load_tmpl("login.html");
# Display the Bad username and password warning
$template->param('INVALID', '1');
}
return $template->output;
}
Hope this helps.
-- RogueFalcon
|
|---|