healy787 Posted March 8, 2009 Share Posted March 8, 2009 Hi guys. I have set up a script to allow access to a hidden page. The script works fine however i want to have the option of adding multiple users.I don't want to use Mysql unless i really have to. Ive heard it maybe possible with arrays? Anyway here is the current script. Thanks very much. <? $user_name = "user"; $password = "password"; $login_user_name = $_POST["login_user_name"]; $login_password = $_POST["login_password"]; $logged_in_for = $_POST["logged_in_for"]; if($login_user_name != $user_name || $login_password != $password) { header("Location: login.php?message=Invalid+user+name+or+password."); exit; } if($login_user_name != $user_name1 || $login_password != $password1) { header("Location: login.php?message=Invalid+user+name+or+password."); exit; } else { setcookie("logged_in", $login_user_name, time()+60*60*24*$logged_in_for, "/"); header("Location: index.php"); exit; } else { setcookie("logged_in", $login_user_name, time()+60*60*24*$logged_in_for, "/"); header("Location: index.php"); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/148523-solved-multiple-passwords-do-i-use-arrays/ Share on other sites More sharing options...
Mchl Posted March 8, 2009 Share Posted March 8, 2009 If you want to stay away from database backend, you could use arrays... Provided you don't expect to have many users. Link to comment https://forums.phpfreaks.com/topic/148523-solved-multiple-passwords-do-i-use-arrays/#findComment-779915 Share on other sites More sharing options...
healy787 Posted March 8, 2009 Author Share Posted March 8, 2009 what would be the max users i could add? Any ideas on how to go about using the Array function? Thank you for your reply. Link to comment https://forums.phpfreaks.com/topic/148523-solved-multiple-passwords-do-i-use-arrays/#findComment-779918 Share on other sites More sharing options...
Mchl Posted March 8, 2009 Share Posted March 8, 2009 The max number would be limited by your ability to do database's job by hand. You would have to manually keep track of all users and their passwords. $userArray = array( "username1" => "password1", "username2" => "password2" ); $login_user_name = $_POST["login_user_name"]; $login_password = $_POST["login_password"]; $logged_in_for = $_POST["logged_in_for"]; if (isset($userArray[$login_user_name])) { //found user in array, check password if ($userArray[$login_user_name] == $login_password) { //password correct, do login } else { //password incorrect, login failed } } else { //user not found } Link to comment https://forums.phpfreaks.com/topic/148523-solved-multiple-passwords-do-i-use-arrays/#findComment-779922 Share on other sites More sharing options...
kickstart Posted March 8, 2009 Share Posted March 8, 2009 Hi If you really don't want to use a database and do it simply then I would be tempted to have an array of the passwords keyed on the user name. <?php $user_name = "user"; $password = array("user" => "password", "user1" => "password1"); $login_user_name = $_POST["login_user_name"]; $login_password = $_POST["login_password"]; $logged_in_for = $_POST["logged_in_for"]; if($password[$login_user_name] != $password) { header("Location: login.php?message=Invalid+user+name+or+password."); exit; } else { setcookie("logged_in", $login_user_name, time()+60*60*24*$logged_in_for, "/"); header("Location: index.php"); exit; } ?> All the best Keith Link to comment https://forums.phpfreaks.com/topic/148523-solved-multiple-passwords-do-i-use-arrays/#findComment-779923 Share on other sites More sharing options...
healy787 Posted March 8, 2009 Author Share Posted March 8, 2009 Fantastic! Thank you guys. Can't thank you enough. Works brilliantly! Many many thanks. Matt Link to comment https://forums.phpfreaks.com/topic/148523-solved-multiple-passwords-do-i-use-arrays/#findComment-779941 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.