perezf Posted September 10, 2006 Share Posted September 10, 2006 i am trying to make this login script using arrays to work but my login always comes back incorrectwhat could be the problem[code]//assigns the username and password$username = array("admin", "frank", "money");$password = array("password", "thepass", "test");//reads the users input and assigns a name$user = $_POST['user'];$pass = $_POST['pass'];//checks to see if the username and password are correctif ($user == $username[count($username)] && $pass == $password[count($password)]) {[/code] Link to comment https://forums.phpfreaks.com/topic/20304-login-form-using-array/ Share on other sites More sharing options...
radalin Posted September 10, 2006 Share Posted September 10, 2006 instead of if ($user == $username[count($username)] && $pass == $password[count($password)]) {tryif ($user == $username[(count($username) - 1)] && $pass == $password[(count($password) - 1)]) {but I'm curious how this authentication works? you can only check if the user is the last user or it will always do the wrong thing.If you intend to define passowords and usernames in an array, which I strongly recommend to keep them in a database, you could something like this. $auth = array("admin" => "password", "frank" => "thepass", "test" => "money");then in your if statement do thisif ( $auth[$user] == $pass ) echo "you logged in..."; Link to comment https://forums.phpfreaks.com/topic/20304-login-form-using-array/#findComment-89405 Share on other sites More sharing options...
perezf Posted September 10, 2006 Author Share Posted September 10, 2006 why do you use -1 Link to comment https://forums.phpfreaks.com/topic/20304-login-form-using-array/#findComment-89407 Share on other sites More sharing options...
radalin Posted September 10, 2006 Share Posted September 10, 2006 because the array begins from 0th element and not first your count($username) will return 3 and there is no element at 3. Instead there are 0,1 and 2. Link to comment https://forums.phpfreaks.com/topic/20304-login-form-using-array/#findComment-89410 Share on other sites More sharing options...
perezf Posted September 10, 2006 Author Share Posted September 10, 2006 ok got it thank you Link to comment https://forums.phpfreaks.com/topic/20304-login-form-using-array/#findComment-89414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.