sheen.andola Posted August 26, 2009 Share Posted August 26, 2009 Hello. The website i am creating is for a conference my school is hosting. What I want to do is give the username and password for each delegation to use; once they log in, they will be directed to a secretpage which contains information pertaining only to their delegation. I found this code, but it doenst seem to redirect to the page I want it to. For $myusernameA for instance, I want her to be directed to a page called conference.php. It just stays in the same page; is there something wrong with the code (below): <?php // This is the list of users, passwords and secret page filenames. // Just change these usernams and the filenames as you prefer. // There are five logins in this demo but it can be expanded fairly simply. $myusernameA="alan"; $mypasswordA="letmein"; $mysecretfileA="conference.php"; $myusernameB="bob"; $mypasswordB="letmein"; $mysecretfileB="secretpageB.htm"; $myusernameC="charles"; $mypasswordC="letmein"; $mysecretfileC="secretpageC.htm"; $myusernameD="david"; $mypasswordD="letmein"; $mysecretfileD="secretpageD.htm"; $myusernameE="edward"; $mypasswordE="letmein"; $mysecretfileE="secretpageE.htm"; // The entry form can be styled anyway you like as long as the mechanics remain the same. // You must use single and not double quotes though throughout. $entryform = " <h1>Client Login</h1> <form action='$PHP_SELF' method='post'> <p>Username: <input name='username' type='text' size='10'> Password: <input name='password' type='password' size='10'></p> <p><input name='Submit' type='submit' value='Submit'></p> </form> "; if(!$password && !$username){ echo "$entryform"; } elseif($password==$mypasswordA&&$username==$myusernameA){include("$mysecretfileA");} elseif($password==$mypasswordB&&$username==$myusernameB){include("$mysecretfileB");} elseif($password==$mypasswordC&&$username==$myusernameC){include("$mysecretfileC");} elseif($password==$mypasswordD&&$username==$myusernameD){include("$mysecretfileD");} elseif($password==$mypasswordE&&$username==$myusernameE){include("$mysecretfileE");} else{ echo"<div style='color:red;'><h2>Incorrect username or password.</h2></div>"; echo "$entryform"; } ?> </body> </html> If the code is terrible, can anyone suggest a code that would allow different logins to open different pages or content. I know it is probably easier to use mysql and I must have spent a week trying to figure it out on my mac, but I cant and I dont have the patience for it anymore. Although using php login without a database is unsecure, I dont have any sensitive files that really need to be protected or can harm in anyway. Any help would be appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 26, 2009 Share Posted August 26, 2009 Ummmm you need tizag or w3ctutorials Anyway, here try this quick code I'll whip up. <?php session_start(); if(!$_POST['Submit']){ echo "<p><form action='".$PHP_SELF."' method='post'> Username: <input name='username' type='text' size='10'/> <br/> Password: <input name='password' type='password' size='10'> <br/> <input name='Submit' type='submit' value='Submit'> </form></p> "; } if($_POST['submit']){ $_SESSION['username'] = $_POST['username']; if($_POST['password'] == "letmein"){ elseif($_POST['username']=="alan"){ header('Location: conference.php'); } elseif($_POST['username']=="bob"){ header('Location: secretpageB.htm'); } elseif($_POST['username']=="charles"){ header('Location: secretpageC.htm'); } elseif($_POST['username']=="david"){ header('Location: secretpageD.htm'); } elseif($_POST['username']=="edward"){ header('Location: secretpageE.htm'); } } else{ echo "Wrong Password!"; } } ?> Of course, there are probably bugs since it's 11:50 at night, I wrote this off the top of my head, and I dunno if that's what you want. Also, this will not check if the usernames are correct, it will just redirect if a specific username is given. Oh, I started a session so that you could say "Hello, USERNAME" or something. Just remember session_start(); Quote Link to comment Share on other sites More sharing options...
sheen.andola Posted August 26, 2009 Author Share Posted August 26, 2009 I probably do need these tutorials and Im trying to learn as much as I can, but this is way too advance for me (I didnt know the difference between php and javascript until an hour ago, and im supposed to maintain the website). In anycase, that is sort of what I want, but each user name will have a different password as well. So username1, unpon entering his password will be directed to a different page ad username2, upon doing the same will be directed to another page and so on... Quote Link to comment Share on other sites More sharing options...
krio Posted August 26, 2009 Share Posted August 26, 2009 or you could try: <?php if (isset ( $_POST ['username'] )) { $password = $_POST ['password']; $username = $_POST ['username']; $myusernameA = "alan"; $mypasswordA = "letmein"; $mysecretfileA = "conference.php"; $myusernameB = "bob"; $mypasswordB = "letmein"; $mysecretfileB = "secretpageB.htm"; $myusernameC = "charles"; $mypasswordC = "letmein"; $mysecretfileC = "secretpageC.htm"; $myusernameD = "david"; $mypasswordD = "letmein"; $mysecretfileD = "secretpageD.htm"; $myusernameE = "edward"; $mypasswordE = "letmein"; $mysecretfileE = "secretpageE.htm"; if ($password == $mypasswordA && $username == $myusernameA) { header ( "Location: $mysecretfileA" ); exit (); } elseif ($password == $mypasswordB && $username == $myusernameB) { header ( "Location: $mysecretfileB" ); exit (); } elseif ($password == $mypasswordC && $username == $myusernameC) { header ( "Location: $mysecretfileC" ); exit (); } elseif ($password == $mypasswordD && $username == $myusernameD) { header ( "Location: $mysecretfileD" ); exit (); } elseif ($password == $mypasswordE && $username == $myusernameE) { header ( "Location: $mysecretfileE" ); exit (); } } ?> <html> <head></head> <body> <h1>Client Login</h1> <form action="" method="post"> <p>Username: <input name='username' type='text' size='10'> Password: <input name='password' type='password' size='10'></p> <p><input name='Submit' type='submit' value='Submit'></p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 26, 2009 Share Posted August 26, 2009 Even better why not also create, the page of the users name on the fly. think everyone lol. that would be on the admin page i guess lol Quote Link to comment Share on other sites More sharing options...
sheen.andola Posted August 26, 2009 Author Share Posted August 26, 2009 That seems to do the trick krio. Thank you very much!! 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.