lukep11a Posted June 27, 2011 Share Posted June 27, 2011 Hi I have the following code to check the user login information, how would I insert code that checks the column 'username' from the table 'selections' for the username entered on login and if it doesn't exist then member-home.php is displayed, and if it does exist then teamselections.php is displayed? <?php function checkLogin($u, $p) { global $seed; // global because $seed is declared in the header.php file if (!valid_username($u) || !valid_password($p) || !user_exists($u)) { return false; // the name was not valid, or the password, or the username did not exist } //Now let us look for the user in the database. $query = sprintf(" SELECT loginid FROM login WHERE username = '%s' AND password = '%s' AND disabled = 0 AND activated = 1 LIMIT 1;", mysql_real_escape_string($u), mysql_real_escape_string(sha1($p . $seed))); $result = mysql_query($query); // If the database returns a 0 as result we know the login information is incorrect. // If the database returns a 1 as result we know the login was correct and we proceed. // If the database returns a result > 1 there are multple users // with the same username and password, so the login will fail. if (mysql_num_rows($result) != 1) { return false; } else { // Login was successfull $row = mysql_fetch_array($result); // Save the user ID for use later $_SESSION['loginid'] = $row['loginid']; // Save the username for use later $_SESSION['username'] = $u; // Now we show the userbox return true; } return false; } ?> Any help would be much appreciated. Thanks Luke Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 27, 2011 Share Posted June 27, 2011 Hi I have the following code to check the user login information, how would I insert code that checks the column 'username' from the table 'selections' for the username entered on login and if it doesn't exist then member-home.php is displayed, and if it does exist then teamselections.php is displayed? something like: "select * from `selections` where `username` = '$username' limit 1" hope this helps Quote Link to comment Share on other sites More sharing options...
lukep11a Posted June 28, 2011 Author Share Posted June 28, 2011 thanks for your reply, how would I then get it to display member-home.php if the username exists and teamselection.php if it doesn't? Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted June 28, 2011 Share Posted June 28, 2011 Assuming the code you posted earlier works, could do something like this maybe? if (checkLogin($user, $pass)) { header('Location: member-home.php'); } else { header('Location: teamselections.php'); } Quote Link to comment Share on other sites More sharing options...
fugix Posted June 28, 2011 Share Posted June 28, 2011 you can also check to see if the session is set if (isset($_SESSION['loginid'])) { header('Location: member-home.php'); } else { header('Location: teamselections.php'); } Quote Link to comment Share on other sites More sharing options...
lukep11a Posted June 28, 2011 Author Share Posted June 28, 2011 I can't get it to work, I don't know if I'm putting the code in the wrong place, I also have the following code in login.php that links to the previous code, should it placed somewhere within this instead? <?php if (!isLoggedIn()) { // user is not logged in. if (isset($_POST['cmdlogin'])) { // retrieve the username and password sent from login form & check the login. if (checkLogin($_POST['username'], $_POST['password'])) { show_userbox(); } else { echo "Incorrect Login information !"; show_loginform(); } } else { // User is not logged in and has not pressed the login button // so we show him the loginform show_loginform(); } } else { // The user is already loggedin, so we show the userbox. show_userbox(); } ?> Quote Link to comment Share on other sites More sharing options...
lukep11a Posted June 28, 2011 Author Share Posted June 28, 2011 I don't think I am explaining myself properly. I have two tables one called 'members' with all the users details in and one called 'selections' where each user is required to make a few selections on their first login. So basically I am asking how I can apply code on login to check to see if the user that has logged in has already made their selections by checking to see if they already exist in the username column of the 'selections' table, and if they do take them to the member homepage 'member-home.php' and if not to the selections page 'teamselections.php'. I hope that makes sense. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
lukep11a Posted June 29, 2011 Author Share Posted June 29, 2011 I have tried applying the code given but so far still can't it to work, are there any other ways it can be done that i can try? or is there a particular place within my code that it needs to be put? I tried placing it at the end of the login.functions.php which is the first set of code? Any help would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 can you post your new code Quote Link to comment Share on other sites More sharing options...
lukep11a Posted June 29, 2011 Author Share Posted June 29, 2011 <?php if (!isLoggedIn()) { // user is not logged in. if (isset($_POST['cmdlogin'])) { // retrieve the username and password sent from login form & check the login. if (checkLogin($_POST['username'], $_POST['password'])) { show_userbox(); } else { echo "Incorrect Login information !"; show_loginform(); } } else { // User is not logged in and has not pressed the login button // so we show him the loginform show_loginform(); } } else { // The user is already loggedin, so we show the userbox. show_userbox(); } "select * from `selections` where `username` = '$username' limit 1" if (checkLogin($user, $pass)) { header('Location: member-home.php'); } else { header('Location: teamselections.php'); } ?> 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.