problem with my login script

From: Date: Tue, 02 Oct 2012 06:52:42 +0000
Subject: problem with my login script
Groups: php.general 
Request: Send a blank email to php-general+get-319323@lists.php.net to get a copy of this message
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

« previous php.general (#319323) next »