I have a login script and run into an error, first heres the code:
use DBI; use CGI qw /:standard/; use CGI::Cookie; use warnings; while (! defined $cookies{'authorized'}) { if (param) { my $username = param('username'); my $password = param('password'); my $dbh = DBI->connect("dbi:SQLite:dbname=/path/to/dat +abase.db","",""); my $sth = $dbh->prepare('select * from useers where username = ? and password = ?' +); $sth->execute($username,$password); my @row = $sth->fetch_array; if (@row) { #login success, set authorized cookie my $cookie = CGI::Cookie->new( -name=>'authorized', -value=>1, -path=>'/default/url'); last; ##THIS IS WHERE I NEED TO + END IT } } print header,start_html('Login'),h1('Login'), start_form, "Username: ",textfield('username'),br, "Password: ",password_field('password'),br, submit("Enter"); end_form, end_html; #######this generates an infinite loop of login forms } #once that specific cookie is set, i redirect print redirect('search.cgi');
So what's happening is
while (! defined $cookies{'authorized'}) { if (param) { if authorized { set cookie } #end here!!!!!!!!!!!!!!!!!! } #if we make it here, user isnt validated, so generate form generate login form } #now that we're out of the loop, redirect redirect
Any way to exit out of the loop?
In reply to How do I end a while loop early? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |