gmz1023 Posted September 4, 2008 Share Posted September 4, 2008 Okay, so i've got my website set up with one form on it. and i want it so that by entering a different password you get sent to a different page. Like if i put in: Zoom, it would take the user to Zoom.php or if i typed in blah it would take me to Blah.php Link to comment Share on other sites More sharing options...
jeffman Posted September 4, 2008 Share Posted September 4, 2008 In your database, the passwords get stored in separate fields. So one field is called Zoom and the other is called blah. When you verify the password, you check it against both fields. The one that matches tells you what destination to send them to. You could hardcode that relationship into your script, or the destination page could also be stored as a field in the DB.Just make sure your users cannot use the same password for both! Link to comment Share on other sites More sharing options...
zppblood Posted September 4, 2008 Share Posted September 4, 2008 If you don't have that many passwords, you can do it like this, but I think Deirdre's Dad's post is better for password protecting than this one because you would do a lot more with it. <?php $password=$_POST['password']; if ($password=='Zoom' || $password=='blah') { header('Location: '.$password.'.php'); }?> Link to comment Share on other sites More sharing options...
gmz1023 Posted September 4, 2008 Author Share Posted September 4, 2008 but I think Deirdre's Dad's post is better for password protecting than this one because you would do a lot more with it.how would i even start with that? i under stand everything up until the script part... Link to comment Share on other sites More sharing options...
rattlsnak Posted September 5, 2008 Share Posted September 5, 2008 How many different passwords are we talking about here? If everyone has a different one, then it would be easier to give everyone a 'user level' and when you fetch the array, certain level users will go to one page, and other to another page. That way you can have multiple users , all with different passwords going to the page you want by their user level. Link to comment Share on other sites More sharing options...
zppblood Posted September 5, 2008 Share Posted September 5, 2008 how would i even start with that? i under stand everything up until the script part...Use MySQL, create a database and tables with the fields you want with it (user ID, username, password, type of user [Admin, Moderator, Regular User, etc.]). Use PHP and MySQL functions to make a connection, select the database you created and the SQL queries you want to use (comparing the usernames and passwords from the form to the ones in the database.)http://www.phpeasystep.com/workshopview.php?id=6 Link to comment Share on other sites More sharing options...
jeffman Posted September 5, 2008 Share Posted September 5, 2008 So this is what you might write to accomplish the task as you described it. I can see reasons why you might want 2 passwords associated with the same account, and I can also see why you might not. This does what you asked for.WARNING: I have not checked this code, but it looks close. (Friends, please correct me where I goof.) I've also left out connection routines, etc., that I assume you already know.Anyway -- use this stuff to create your table (or create it in your admin panel): $QUERY = "CREATE TABLE `users` ( `username` VARCHAR( 32 ), `pw1` VARCHAR( 32 ), `pw2` VARCHAR( 32 ) )"; $result = mysql_query($QUERY); Use this to register a new user: $username = $_POST['username']; $pw1 = $_POST['pw1']; $pw2 = $_POST['pw2']; $QUERY = "INSERT INTO `users` ( `username`, `pw1`, `pw2` ) VALUES ( '$username', MD5( '$pw1' ), MD5( '$pw2' ) )"; $result = mysql_query($QUERY); And use this to check passwords and send user to the right page $username = $_POST['username']; $pw = $_POST['pw']; $result = mysql_query("SELECT pw1, pw2 FROM users WHERE username='$username'"); $pw_ra = mysql_fetch_array( $result, MYSQL_ASSOC ); if (md5($pw) == $pw_ra[0]) { // start session etc. header ('Location: dest0.php'); } elseif (md5($pw) == $pw_ra[1]) { // start session etc. header ('Location: dest1.php'); } else { // handle bad input data } I'm assuming you can create the correct forms for posting all this data. I've also kept it bare-bones. Your table probably requires additional fields. You'll also want to validate your input data before putting it into a query. No problem. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.