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] Quote Link to comment 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..."; Quote Link to comment Share on other sites More sharing options...
perezf Posted September 10, 2006 Author Share Posted September 10, 2006 why do you use -1 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
perezf Posted September 10, 2006 Author Share Posted September 10, 2006 ok got it thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.