Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I end a while loop early?
by ig (Vicar) on May 08, 2013 at 07:57 UTC | |
|
Re: How do I end a while loop early?
by LanX (Saint) on May 07, 2013 at 23:50 UTC | |
by davido (Cardinal) on May 08, 2013 at 00:25 UTC | |
by LanX (Saint) on May 08, 2013 at 00:56 UTC | |
by Anonymous Monk on May 08, 2013 at 09:15 UTC | |
|
Re: How do I end a while loop early?
by choroba (Cardinal) on May 07, 2013 at 23:48 UTC |