Re: problem with my login script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux