Rifts Posted September 8, 2010 Share Posted September 8, 2010 I have an array $INFO = array( 'joebob' => 'password', 'fred' => 'password', 'tom'=> 'password' ); how can i just do a simple check to see if a name and password match? something like if (in_array(can'tthink)); thanks Quote Link to comment https://forums.phpfreaks.com/topic/212915-simple-brain-fart-question/ Share on other sites More sharing options...
wildteen88 Posted September 8, 2010 Share Posted September 8, 2010 I guess you have a form setup like so <form action="" method="post"> Username: <input type="text" name="username" /><br /> Password: <input type="text" name="password" /><br /> <input type="submit" name="submit" value="Login" /> </form> And an array of users $authUsers = array ( 'Joe' => 'pass1', 'Sam' => 'pass2', 'Bob' => 'pass3' ); To see of the entered username/password is valid you'd do if(isset($_POST['username'], $_POST['password'])) { $user = $_POST['username']; $pass = $_POST['password']; if(isset($authUsers[$user]) && $authUsers[$user] == $pass) { echo '<h1>Success! You are a valid user</h1>'; } else { echo 'Sorry but the username/password are incorrect'; } } Quote Link to comment https://forums.phpfreaks.com/topic/212915-simple-brain-fart-question/#findComment-1108960 Share on other sites More sharing options...
Rifts Posted September 9, 2010 Author Share Posted September 9, 2010 perfect thanks Quote Link to comment https://forums.phpfreaks.com/topic/212915-simple-brain-fart-question/#findComment-1108969 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.