dprichard Posted June 18, 2007 Share Posted June 18, 2007 I am trying to set 3 sessions upon login but when I try to echo the session info on the following page it doesn't do anything. Here is my login form and below that is where I am trying to call the session on the following page. Any assistance would be greatly appreciated!!! <?php session_start(); require_once('../Connections/prbc.php'); if(isset($_POST['login'])){ $username = ''; $password = ''; if (isset ($_POST['username']) && $_POST['username'] != '') $username = $_POST['username']; if(isset ($_POST['password']) && $_POST['password'] != '') $password = $_POST['password']; $username = mysql_real_escape_string( $username ); $password = mysql_real_escape_string( $password ); $db_password = md5($password); mysql_select_db('prbcweb') or die(mysql_error()); $login = mysql_query("SELECT * FROM prbc_user WHERE `user_name` = '$username' AND `user_pass` = '$db_password'"); $row_login = mysql_fetch_array($login); $row_login_total = mysql_num_rows($login); if ($row_login_total == 1) { $_SESSION['MM_Username'] = $row_login['user_name']; $_SESSION['UID'] = $row_login['user_id']; $_SESSION['auth_level'] = $row_login['user_access_level']; header("Location: approver.php"); } elseif ($row_login_total <> 1) { header("Location: login_2.php"); } } ?> Second Page <?php session_start(); if(isset($_SESSION['MM_Username'])) {echo $_SESSION['MM_Username']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/ Share on other sites More sharing options...
Full-Demon Posted June 18, 2007 Share Posted June 18, 2007 You need only one session and perhaps the auth one if you think thats handy. Just use user_id. If you want to give every client a unique ID, dont use IP address, but sessions with a random id...IP address might be the same of different clients...ie a lan. FD Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/#findComment-276795 Share on other sites More sharing options...
dprichard Posted June 18, 2007 Author Share Posted June 18, 2007 So, I can't set multiple sessions? Even if I take the other two out and just use this on the next page <?php session_start(); echo $_SESSION['MM_Username']; ?> I am still getting an error: Notice: Undefined index: MM_Username in C:\root\admin\approver.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/#findComment-276801 Share on other sites More sharing options...
dprichard Posted June 18, 2007 Author Share Posted June 18, 2007 Bump.... Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/#findComment-276817 Share on other sites More sharing options...
per1os Posted June 18, 2007 Share Posted June 18, 2007 <?php session_start(); if (!isset($_SESSION['MM_Username'])) { $_SESSION['MM_Username'] = 'Test Name'; echo '<a href="' . $_SERVER['PHP_SELF'] . '">Click Here</a>'; }else { echo "It Worked!!!<br />MM_Username = " . $_SESSION['MM_Username']; } ?> You are not defining the variable $_SESSION['MM_Username'] before you call it, and since there is no definition for that index, php sees it as undefined and thus throws a "Notice" error. Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/#findComment-276840 Share on other sites More sharing options...
dprichard Posted June 18, 2007 Author Share Posted June 18, 2007 I was trying to assign it on the page before. Is that not going to stay from page to page? if ($row_login_total == 1) { $_SESSION['MM_Username'] = $row_login['user_name']; $_SESSION['UID'] = $row_login['user_id']; $_SESSION['auth_level'] = $row_login['user_access_level']; header("Location: approver.php"); Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/#findComment-276842 Share on other sites More sharing options...
per1os Posted June 18, 2007 Share Posted June 18, 2007 The header tag tends to throw off setting session variables. Suggest a Javascript or Meta redirect. if ($row_login_total == 1) { $_SESSION['MM_Username'] = $row_login['user_name']; $_SESSION['UID'] = $row_login['user_id']; $_SESSION['auth_level'] = $row_login['user_access_level']; echo "<script type=text/javascript>location.href='approver.php'</script>"; Should work. Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/#findComment-276846 Share on other sites More sharing options...
Illusion Posted June 18, 2007 Share Posted June 18, 2007 and also make sure that you have session_start(); statement before assigning the values on the page Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/#findComment-276850 Share on other sites More sharing options...
dprichard Posted June 18, 2007 Author Share Posted June 18, 2007 The header tag tends to throw off setting session variables. Suggest a Javascript or Meta redirect. Thank you!!! You are the freaking man! Been fighting this one all morning! Quote Link to comment https://forums.phpfreaks.com/topic/56047-solved-problem-setting-sessions-upon-login/#findComment-276852 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.