web_master Posted June 13, 2008 Share Posted June 13, 2008 hi, I got a password protected page. How can I give a more tha one password? Now is a password "admin", but I want to use the other words too... thnx <?php // Password $password = "admin"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Password protected area</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> <!-- p { font-size: 9px; color: #000000; font-family: Verdana, Tahoma, Arial } td { font-size: 9px; color: #000000; font-family: Verdana, Tahoma, Arial } --> </style> </head> <body> <?php print "<h2 align=\"center\">Password protected area</h2>"; // If password is valid let the user get access if (isset($_POST["password"]) && ($_POST["password"] == $password)) { ?> <!-- hidden contents --> <p align="center">Password is correct</p> <!-- # hidden contents # --> <?php } else { // Wrong password or no password entered display this message if (isset($_POST['password']) || $password == "") { print "<p align=\"center\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>";} print "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>"; print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>"; } ?> <br /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/110102-solved-more-than-1-password/ Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 Setup an array of possible passwords then check to see if the provided password is in the password array // set up array of possible passwords $passwords = array('pass1', 'pass2', 'pass3', 'etc..'); ... // check to see if the provided password is in the password array if (isset($_POST["password"]) && (in_array($_POST['password'], $passwords)) { // user logged in! } Quote Link to comment https://forums.phpfreaks.com/topic/110102-solved-more-than-1-password/#findComment-565044 Share on other sites More sharing options...
web_master Posted June 13, 2008 Author Share Posted June 13, 2008 Setup an array of possible passwords then check to see if the provided password is in the password array // set up array of possible passwords $passwords = array('pass1', 'pass2', 'pass3', 'etc..'); ... // check to see if the provided password is in the password array if (isset($_POST["password"]) && (in_array($_POST['password'], $passwords)) { // user logged in! } This is what I got: Warning: Wrong parameter count for in_array() in d:\internet\pass.php on line 32 <?php // Password $passwords = array('admin', 'powerg3'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Password protected area</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> <!-- p { font-size: 9px; color: #000000; font-family: Verdana, Tahoma, Arial } td { font-size: 9px; color: #000000; font-family: Verdana, Tahoma, Arial } --> </style> </head> <body> <?php print "<h2 align=\"center\">Password protected area</h2>"; // If password is valid let the user get access if (isset($_POST["password"]) && (in_array($_POST["password"]) == $passwords)) { ?> <!-- hidden contents --> <p align="center">Password is correct</p> <!-- # hidden contents # --> <?php } else { // Wrong password or no password entered display this message if (isset($_POST['password']) || $password == "") { print "<p align=\"center\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>";} print "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>"; print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>"; } ?> <br /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/110102-solved-more-than-1-password/#findComment-565068 Share on other sites More sharing options...
jonsjava Posted June 13, 2008 Share Posted June 13, 2008 <?php // set up array of possible passwords $passwords = array('pass1', 'pass2', 'pass3', 'etc..'); // check to see if the provided password is in the password array if (isset($_POST["password"]) && (in_array($_POST['password'], $passwords))) { // user logged in! } Quote Link to comment https://forums.phpfreaks.com/topic/110102-solved-more-than-1-password/#findComment-565080 Share on other sites More sharing options...
web_master Posted June 13, 2008 Author Share Posted June 13, 2008 THNX Quote Link to comment https://forums.phpfreaks.com/topic/110102-solved-more-than-1-password/#findComment-565084 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 How come people can't copy and paste any more? Also, if you start getting a lot of passwords, you may just want to make a membership system. Quote Link to comment https://forums.phpfreaks.com/topic/110102-solved-more-than-1-password/#findComment-565110 Share on other sites More sharing options...
prcollin Posted June 13, 2008 Share Posted June 13, 2008 How come people can't copy and paste any more? Also, if you start getting a lot of passwords, you may just want to make a membership system. either htat or just give everyone the same general password if its just for one page. Quote Link to comment https://forums.phpfreaks.com/topic/110102-solved-more-than-1-password/#findComment-565122 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.