I am a newbie to Perl, and I have been trying to set up a login screen for a Web site. When I login to Yahoo or Google I enter my UserID and Password and click the Submit button and go directly to the opening screen. On my screen, I have set up a login form with UserID and Password fields. When the user clicks submit I check the MySQL database and then I have to display a button to click so I have a triggering event to move on to the next screen. Is there a better way?
Here is my code:
#!/usr/bin/perl -w use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use CGI::Pretty; use CGI qw(:standard :cgi-lib -debug fatalsToBrowser); use DBD::mysql; use DBI; my $cgi = new CGI; my ($dbh, $selectstr, $sth, @row, $uid, $psw); my ($numrecs, $numrows, $select_str); my $CoordCookie = cookie(-name=>'MGH_Coord',-value=>0,-path=>'/',-doma +in=>'.rbhyland.org'); print $cgi->header(-cookie=>$CoordCookie,-Cache_Control=>'no-cache'); print start_html(-title =>'HortLine Database Sign In', -style =>'http://www.HortLine.rbhyland.org/Styles.css +', -script=>{-language=>'JAVASCRIPT', -src=>'http://www.HortLine.rbhyland.org/Scripts.js'}) +; print "<div class='header'>", "<h1><img src='http://www.hortline.rbhyland.org/MGLogo.jpg' alt='M +G logo' align='left' />", " Penn State Consumer<br /><br /> Horticultural Help Lin +e</h1><br />"; if (!param('uid')) { print start_form(-method=>"POST",-action=>"http://hortline.rbhylan +d.org/Login.cgi"), "<div align='center' style='border:medium;border-style:sol +id;'>", p,"User ID ",textfield(-name=>'uid',-id=> +'uid',-value=>'',-size=>20,-maxlength=>50), p,"Password ",password_field(-name=>'psw', -id=>'psw' +, -value=>'', -size=>20, -maxlength=>50), p,submit(-name=>'submit', -value=>'Login'), "</div>", end_form ; } else { $uid=param('uid'); $psw=param('psw'); $dbh = DBI->connect("","","", { RaiseError => 1,AutoCommit => 1 }) or &dienice("Can't connect to database: $DBI::errstr"); $selectstr = "select * from Users where Uid = ? AND Psw = ?"; $sth = $dbh->prepare($selectstr) or &dbdie; $sth->execute($uid,$psw) or &dbdie; my @UP = $sth->fetchrow_array(); if (!@UP) { &dienice(qq(User/Psw incorrect. Go to the <a href = "Login.cgi +">Login</a> page and try again.)); } else { print start_form(-method=>"post",-action=>"http://hortline.rbh +yland.org/Switchboard.cgi"), hidden('userid',"$UP[0]"), hidden('county',"$UP[2]"), hidden('coord',"$UP[3]"), hidden('state',"$UP[4]"), br,br,"<center>", submit(-name=>'GotoSwitchboard', -value=>'Go To Main Menu'), "</center>", end_form; } } print end_html; sub dienice { my ($msg) = @_; print "<b>$msg</b>"; exit; } sub dbdie { my ($errmsg) = "$DBI::errstr<br />"; &dienice($errmsg); }
In reply to How do I Implement a One-Click Login Screen on the Web? by rbhyland
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |