Re: problem with my login script
| From: | Rodrigo Silva dos Santos | Date: | Tue, 02 Oct 2012 09:39:54 +0000 |
| Subject: | Re: problem with my login script | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-319324@lists.php.net to get a copy of this message | ||
Hello Thomas.
The if are being evaluated in all iterations of the while, the problem is you didn't stop the
loop when it finds what it's searching for. Try putting a break in the end of the if, them,
when the condition match, the while will stop.
And hey! You're using a lot of legacy code for one that is learning php. If you want, I can
give you some tips to modernize your script ;)
Regards, Rodrigo Silva dos Santos.
Enviado por Samsung Mobile
Thomas Conrad <koopasforever@gmail.com> escreveu:
I'm currently learning php and as a challenge, I'm creating a login
script using text files to store the information (until I learn how to
handle databases with php).
The problem I'm having is the if statement in my while loop is only
evaluated on the last iteration of the while loop, so its only
comparing the last username in the file and no others.
Heres the code:
<?php
session_start();
$users = file("../inc/users.inc.php");
if($_POST['username'] && $_POST['password']){
if(ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $_POST['username'])){
while(list($id ,$username) = each($users)){
if($_POST['username'] == $username){
$_SESSION['logged_in'] = 1;
$_SESSION['username'] = $username;
}
}
if($_SESSION['logged_in'] != 1){
$error = "2";
}
}else{
$error = "4";
}
}else{
$error = "3";
}
if($error){
header("Location: http://koopasforever.com/scripts/login.php?error=$error");
}else{
header("Location: http://koopasforever.com/");
}
?>
I have checked all my variables and they all contain the proper information
Some help would be greatly appriciated, Thanks
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php