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 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. 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 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']; 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 ... 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! 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. 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! 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']; Link to comment https://forums.phpfreaks.com/topic/260206-undefined-index/#findComment-1333711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.