lookinfreshuk Posted September 25, 2010 Share Posted September 25, 2010 hello, i want to create a client login system so when they use there login it redirects them to a page only for them, is this possible? i am using the following code but it only re-drirects them after login to the "index.php" page not the 2nd user to "Harts.php", what am i doing wrong?, thanks <?php $usernames = array("admin","admin2"); $passwords = array("admin","admin2"); $page = array("index.php","Harts.php"); for($i=0;$i<count($usernames);$i++) { $logindata[$usernames[$i]]=$passwords[$i]; } $found = 0; for($i=0;$i<count($usernames);$i++) { if ($usernames[$i] == $_POST["username"]) { $found = 1; } } if ($found == 0) { header('Location: login.php?value=fail'); exit; } if($logindata[$_POST["username"]]==$_POST["password"]) { session_start(); $_SESSION["username"]=$_POST["username"]; header('Location: '.$page); exit; } else { header('Location: login.php?value=fail'); exit; } ?> Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted September 25, 2010 Share Posted September 25, 2010 Hey LookinfreshUK, try the following in place of your current code. <?PHP $usernames = array('admin','admin2'); $passwords = array('admin','admin2'); $page = array('index.php','Harts.php'); // Count the amount of users in array. $count_users = count($usernames); // Set users found to "0". $user_found = '0'; // Set username and password variables from $_POST data. $username = $_POST['username']; $password = $_POST['password']; // Check to see if we have a match in usernames // If we have a match set a variable with the record number // Update "$user_found" if we find a match for($u=0; $u<$count_users; $u++) { if($username == $usernames[$u]) { $userRecord = $u; $user_found = '1'; } } // If no user is found, login has failed. Re-direct back to login. if(!$user_found) { header('Location: login.php?value=fail'); exit; } // If usernames don't match, login has failed. Re-direct back to login. if($usernames[$userRecord] != $username) { header('Location: login.php?value=fail'); exit; // If passwords don't match, login has failed. Re-direct back to login. } else if($passwords[$userRecord] != $password) { header('Location: login.php?value=fail'); exit; // If usernames and passwords match, login succeeded. Re-directed to player specific page. } else { $_SESSION['username'] = $username; header("Location: $page[$userRecord]"); exit; } ?> Tell me if it works or not bud Regards, Paul. Quote Link to comment Share on other sites More sharing options...
lookinfreshuk Posted September 26, 2010 Author Share Posted September 26, 2010 NEW CODE AS YOU PUT ^^ <?PHP $usernames = array('admin','harts'); $passwords = array('admin','harts'); $page = array('index.php','Harts.php'); // Count the amount of users in array. $count_users = count ($usernames); // Set users found to "0" $user_found = '0'; // Set username and password variables from $_POST data. $username = $_POST['username']; $password = $_POST['password']; // Check to see if we gave a match in usernames // If we have a match set a cariable with the record number // Update "$user_found" if we find a match for($u=0; $u<$count_users; $u++) { if($username == $usernames[$u]) { $userRecord = $u; $user_found = '1'; } } // If no user is found, login has failed. Re-direct back to login. if(!$user_found) { header('Location: login.php?value=fail'); exit; } // If usernames don't match, login has failed. Re-direct back to login. if($usernames[$userRecord] !=$username) { header('Location: login.php?value=fail'); exit; // If passwords don't match, login has faled. Re-direct back to login. } else if($passwords[$userRecord] !=$password) { header('Location: login.php?vale=fail'); exit; // If usernames and passwords match, login succeeded. Re-direct to player specific page. } else { $_SESSION['username'] = $username; header("Location: $page[$userRecord]"); exit; } ?> wont even allow the login, it wont move page, just says login failed... :S thanks for the try tho! Quote Link to comment Share on other sites More sharing options...
lookinfreshuk Posted September 27, 2010 Author Share Posted September 27, 2010 anyone else got any ideas? Quote Link to comment Share on other sites More sharing options...
thomashw Posted September 27, 2010 Share Posted September 27, 2010 Can you post the full code, including the form? 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.