anton_1 Posted April 2, 2012 Share Posted April 2, 2012 want to carry over session to help page? but getting the error undefined index. Any help would be greatly appreciated! //getting my value from database table and put it into session $_SESSION["user_firstname"] = $data["Firstname"]; //decides on where the user gets re-directed to. if ($_SESSION["user_priority"] == '1') { header("Location: AdminSection.php"); } else { header("Location:LoggedIn.php"); } if ($_SESSION["user_times_loggged_in"] == '0') { header("Location:UsingTheSystem.php"); } //Help page <?php session_start(); $name = $_SESSION["user_firstname"]; echo $name; ?> any idea why its not picking up the session? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/ Share on other sites More sharing options...
batwimp Posted April 2, 2012 Share Posted April 2, 2012 You also need to run session_start() on the original page where you set your session variables. Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333654 Share on other sites More sharing options...
anton_1 Posted April 2, 2012 Author Share Posted April 2, 2012 thank you for batwimp for your reply, yes i set the session_start on the start page aswell Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333659 Share on other sites More sharing options...
batwimp Posted April 2, 2012 Share Posted April 2, 2012 Try using single quotes for your array indexes: $_SESSION["user_firstname"] = $data["Firstname"]; becomes: $_SESSION['user_firstname'] = $data['Firstname']; Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333660 Share on other sites More sharing options...
floridaflatlander Posted April 2, 2012 Share Posted April 2, 2012 What are you getting the indefined index on, user_firstname or user_priority? Both? anyway try, if (isset($_SESSION['user_priority']) && ($_SESSION['user_priority'] == '1')) { header("Location: AdminSection.php"); } else ... Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333662 Share on other sites More sharing options...
anton_1 Posted April 2, 2012 Author Share Posted April 2, 2012 iv already got the session variables showing on the logged in page with double quotes but the variables will not show in help page? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333664 Share on other sites More sharing options...
batwimp Posted April 2, 2012 Share Posted April 2, 2012 Where are you redirecting to the help page? I can't see that part in your code. I see headers to other pages, but not the help page. Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333666 Share on other sites More sharing options...
anton_1 Posted April 2, 2012 Author Share Posted April 2, 2012 this is where I re-direct to the help page: if ($_SESSION["user_times_loggged_in"] == '0') { header("Location:UsingTheSystem.php"); } thanks! Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333707 Share on other sites More sharing options...
batwimp Posted April 2, 2012 Share Posted April 2, 2012 Are you sure this line is actually populating the session variable: $_SESSION["user_firstname"] = $data["Firstname"]; What happens if, right after this line, you do this: echo $_SESSION['user_firstname']; Quote Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333711 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.