levidyllan Posted January 1, 2008 Share Posted January 1, 2008 I have the following login page that logs users into another restricted page. But when i get to the next page how can I get the ID and details from the db of that member, can someone guide me in the right direction? Log in Page: <?php // *** Validate request to login to this site. session_start(); $loginFormAction = $_SERVER['PHP_SELF']; if (isset($accesscheck)) { $GLOBALS['PrevUrl'] = $accesscheck; session_register('PrevUrl'); } if (isset($_POST['userN'])) { $loginUsername=$_POST['userN']; $password=$_POST['passsW']; $MM_fldUserAuthorization = "auth"; $MM_redirectLoginSuccess = "Private.php"; $MM_redirectLoginFailed = "index.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_reConn, $reConn); $LoginRS__query=sprintf("SELECT ref_name, ref_pass, ref_auth FROM ref_members WHERE ref_name='%s' AND ref_pass='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $reConn) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'ref_auth'); //declare two session variables and assign them $GLOBALS['MM_Username'] = $loginUsername; $GLOBALS['MM_UserGroup'] = $loginStrGroup; //register the session variables session_register("MM_Username"); session_register("MM_UserGroup"); if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/ Share on other sites More sharing options...
revraz Posted January 1, 2008 Share Posted January 1, 2008 When they Login, store their ID into a Session like you do the other variables. Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/#findComment-427338 Share on other sites More sharing options...
pocobueno1388 Posted January 1, 2008 Share Posted January 1, 2008 It looks like you are registering their username on this line session_register("MM_Username"); Just as a note, unless your using an old version of PHP, you should be registering your sessions like this $_SESSION['MM_Username'] = "Their Username"; I'm assuming that their username is unique. So to get their information on another page, you would just do a query like this. <?php session_start(); $query = mysql_query("SELECT username, col, col3 FROM users WHERE username='{$_SESSION['username']}'")or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/#findComment-427342 Share on other sites More sharing options...
levidyllan Posted January 2, 2008 Author Share Posted January 2, 2008 thanks guys, I will give this ago, soon and let you know if it not working, thanks again Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/#findComment-428593 Share on other sites More sharing options...
levidyllan Posted January 2, 2008 Author Share Posted January 2, 2008 pocobueno1388 you mentioned using the following: $_SESSION['MM_Username'] = "Their Username"; In my log in code then would I replace what I have : //declare two session variables and assign them $GLOBALS['MM_Username'] = $loginUsername; $GLOBALS['MM_UserGroup'] = $loginStrGroup; //register the session variables session_register("MM_Username"); session_register("MM_UserGroup"); with //declare two session variables and assign them $GLOBALS['MM_Username'] = $loginUsername; $GLOBALS['MM_UserGroup'] = $loginStrGroup; //register the session variables $_SESSION['MM_Username'] = "MM_Username"; $_SESSION['MM_UserGroup'] = "MM_UserGroup"; or simply do away with the globals and have the following: //register the session variables $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; Thanks Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/#findComment-428636 Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 $_SESSIONS are global, so it would be redundant if you used both. Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/#findComment-428659 Share on other sites More sharing options...
levidyllan Posted January 2, 2008 Author Share Posted January 2, 2008 thanks revraz, posted as I was reply to mine as well. I went in and reduced the code and used $_SESSION['MM_Username'] = $loginUsername; and then used a simple echo to display the session on the other page and it displayed so answered that my self the best way try it... thanks so far Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/#findComment-428671 Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 That's what I say, what's the worse that can happen right? the best way try it... Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/#findComment-428677 Share on other sites More sharing options...
levidyllan Posted January 2, 2008 Author Share Posted January 2, 2008 That's what I say, what's the worse that can happen right? the best way try it... oh! you would not imagine, yup you probably would. but I find it the best way and thats how I learnt PHP etc thanks again peps :-) Quote Link to comment https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/#findComment-428707 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.