My problem was solved no need to argue. I don't see why use a while loop with a count variable when it produces the same result as a foreach loop. As for using a break in the loop, I could add it but the loop is gonna stop anyway as soon as it hits the end of the array. I also didn't see the point in using the explode() function as long as I remove the (in my opinion) useless index numbers from the text file containing the username. The following code works as I expect it to: <?php session_start(); $users = file("../inc/users.inc.php"); if(!empty($_POST['username']) && !empty($_POST['password'])){ if(filter_var($_POST['username'], FILTER_VALIDATE_EMAIL)){ foreach($users as $row){ $row = trim($row); if($_POST['username'] == $row){ $_SESSION['logged_in'] = 1; $_SESSION['username'] = $row; } } if($_SESSION['logged_in'] != 1){ $error = "2"; } }else{ $error = "4"; } }else{ $error = "3"; } if($error){ header("Location:"); }else{ header("Location:"); } ?> users.inc.php: my@xxxxxxxxxx my@xxxxxxxxxx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php