keyboard Posted February 12, 2005 Share Posted February 12, 2005 1) I have a login page which writes username and password into a database. After login the server behavior swich to a login_ok.php or a login_fail.php. Thusfar every works fine. But in the login_ok I want to use the session variable MM_username created by the login page. In the datababindings panel I created a session variable MM_username and dragt it into the page. This doesn't work. What do I do wrong? I have even defined a recordset in the login page: session variable = MM_username. Still no succes. 2) Can I use the session variable MM_UserGroup to display the access level of the user? This my login page : php require_once('Connections/conn_Dmenu.php'); [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php [/span][span style=\"color:#007700\"]require_once([/span][span style=\"color:#DD0000\"]\'Connections/conn_Dmenu.php\'[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]?> <?php mysql_select_db[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$database_conn_Dmenu[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$conn_Dmenu[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]$query_rstUsers [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"SELECT * FROM tblUsers\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$rstUsers [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$query_rstUsers[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$conn_Dmenu[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]()); [/span][span style=\"color:#0000BB\"]$row_rstUsers [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_fetch_assoc[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$rstUsers[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]$totalRows_rstUsers [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_num_rows[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$rstUsers[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]?> <?php [/span][span style=\"color:#FF8000\"]// *** Validate request to login to this site. [/span][span style=\"color:#0000BB\"]session_start[/span][span style=\"color:#007700\"](); [/span][span style=\"color:#0000BB\"]$loginFormAction [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_SERVER[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'PHP_SELF\'[/span][span style=\"color:#007700\"]]; if (isset([/span][span style=\"color:#0000BB\"]$accesscheck[/span][span style=\"color:#007700\"])) { [/span][span style=\"color:#0000BB\"]$GLOBALS[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'PrevUrl\'[/span][span style=\"color:#007700\"]] = [/span][span style=\"color:#0000BB\"]$accesscheck[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]session_register[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\'PrevUrl\'[/span][span style=\"color:#007700\"]); } if (isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'Username\'[/span][span style=\"color:#007700\"]])) { [/span][span style=\"color:#0000BB\"]$loginUsername[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'Username\'[/span][span style=\"color:#007700\"]]; [/span][span style=\"color:#0000BB\"]$password[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'UserPw\'[/span][span style=\"color:#007700\"]]; [/span][span style=\"color:#0000BB\"]$MM_fldUserAuthorization [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"UserStatus\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$MM_redirectLoginSuccess [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"login_ok.php\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$MM_redirectLoginFailed [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"login_fail.php\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$MM_redirecttoReferrer [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]false[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]mysql_select_db[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$database_conn_Dmenu[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$conn_Dmenu[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]$LoginRS__query[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]sprintf[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"SELECT UserName, UserPw, UserStatus FROM tblUsers WHERE UserName=\'%s\' AND UserPw=\'%s\'\"[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]get_magic_quotes_gpc[/span][span style=\"color:#007700\"]() ? [/span][span style=\"color:#0000BB\"]$loginUsername [/span][span style=\"color:#007700\"]: [/span][span style=\"color:#0000BB\"]addslashes[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$loginUsername[/span][span style=\"color:#007700\"]), [/span][span style=\"color:#0000BB\"]get_magic_quotes_gpc[/span][span style=\"color:#007700\"]() ? [/span][span style=\"color:#0000BB\"]$password [/span][span style=\"color:#007700\"]: [/span][span style=\"color:#0000BB\"]addslashes[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$password[/span][span style=\"color:#007700\"])); [/span][span style=\"color:#0000BB\"]$LoginRS [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$LoginRS__query[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$conn_Dmenu[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]()); [/span][span style=\"color:#0000BB\"]$loginFoundUser [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_num_rows[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$LoginRS[/span][span style=\"color:#007700\"]); if ([/span][span style=\"color:#0000BB\"]$loginFoundUser[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]$loginStrGroup [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_result[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$LoginRS[/span][span style=\"color:#007700\"],[/span][span style=\"color:#0000BB\"]0[/span][span style=\"color:#007700\"],[/span][span style=\"color:#DD0000\"]\'UserStatus\'[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#FF8000\"]//declare two session variables and assign them [/span][span style=\"color:#0000BB\"]$GLOBALS[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'MM_Username\'[/span][span style=\"color:#007700\"]] = [/span][span style=\"color:#0000BB\"]$loginUsername[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$GLOBALS[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'MM_UserGroup\'[/span][span style=\"color:#007700\"]] = [/span][span style=\"color:#0000BB\"]$loginStrGroup[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#FF8000\"]//register the session variables [/span][span style=\"color:#0000BB\"]session_register[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"MM_Username\"[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]session_register[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"MM_UserGroup\"[/span][span style=\"color:#007700\"]); if (isset([/span][span style=\"color:#0000BB\"]$_SESSION[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'PrevUrl\'[/span][span style=\"color:#007700\"]]) && [/span][span style=\"color:#0000BB\"]false[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]$MM_redirectLoginSuccess [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_SESSION[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'PrevUrl\'[/span][span style=\"color:#007700\"]]; } [/span][span style=\"color:#0000BB\"]header[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"Location: \" [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]$MM_redirectLoginSuccess [/span][span style=\"color:#007700\"]); } else { [/span][span style=\"color:#0000BB\"]header[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"Location: \"[/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]$MM_redirectLoginFailed [/span][span style=\"color:#007700\"]); } } [/span][span style=\"color:#0000BB\"]?> [/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] ************************************************************* This is my login_ok page: <body> <h4>Login succesfull</h4> <p>You are loged in as : <?php echo $_SESSION['MM_Username']; ?></p> <p>Your status is : </p> <p><a href="index.php">Back to homepage</a> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/2162-session-variable/ Share on other sites More sharing options...
keyboard Posted February 19, 2005 Author Share Posted February 19, 2005 DW doesn't add the code 'session_start()' automatically to the login_ok page when dragging the session var to the login_ok page. . I had to insert it manually into the code. Every page where I use a session variable must have this piece of code. Now it works :-) Anybody knows why DW doesn't add this code by default when you drag a session variable into a php-page. Quote Link to comment https://forums.phpfreaks.com/topic/2162-session-variable/#findComment-7140 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.