thunder708 Posted March 3, 2010 Share Posted March 3, 2010 hi all! right i have two files, login.php and users.php. users.php <? $user = array(); // Set Users $user[0]["name"]='liam'; $user[0]["pass"]='lol'; $user[1]["name"]='mike'; $user[1]["pass"]='rofl'; ?> and in the login.php i have a form that you type in a user and pass and it logs you in, i know how to do this if i set the values within the login file itself but i want to be able to use this array i have made. so my question is, how do i search the array for the required user and pass when it is submitted from the form? Quote Link to comment Share on other sites More sharing options...
trq Posted March 3, 2010 Share Posted March 3, 2010 foreach ($user as $u) { if ($u['name'] == $_POST['name'] && $u['pass'] == $_POST['pass']) { // username password matches. } } Quote Link to comment Share on other sites More sharing options...
thunder708 Posted March 3, 2010 Author Share Posted March 3, 2010 thanks, this works if i put the contents of users.php into the main file but doesnt work if i include the file... any ideas? Quote Link to comment Share on other sites More sharing options...
trq Posted March 3, 2010 Share Posted March 3, 2010 Including the file should work fine. Post your code. Quote Link to comment Share on other sites More sharing options...
thunder708 Posted March 3, 2010 Author Share Posted March 3, 2010 $user = $_REQUEST['user']; // requests user from form $pass = $_REQUEST['pass']; // requests pass from form include("users.php"); foreach ($users as $u) { if ($u['name'] == $user && $u['pass'] == $pass) { echo "well don eyou have logged in "; } } Quote Link to comment Share on other sites More sharing options...
thunder708 Posted March 3, 2010 Author Share Posted March 3, 2010 i have figured out what i have done wrong, i had changed your code to say foreach ($users as $u) { and changed the users file to say $users[0]["name"]='liam'; $users[0]["pass"]='lol'; but forgot to change the declaration to $users = array(); it was still $user = array(); my bad thank you anyway 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.