nblackwood Posted February 18, 2010 Share Posted February 18, 2010 I have an issue with sessions. I need to set a session, register session id and start session. I need the session data I use with $_SESSION to be visible on the confirmation page. I know it should work, but for some reason, it's not. Here's some code: <?php session_id(); session_register(); session_start(); $_SESSION["Name"]; ?> Here's the code I'm using to retrieve session data: <?php echo $_SESSION["Name"];?> Someone please tell me what I'm doing wrong, or not doing. Thanks for any input. Link to comment https://forums.phpfreaks.com/topic/192469-session-problems/ Share on other sites More sharing options...
premiso Posted February 18, 2010 Share Posted February 18, 2010 session_start sets the id and registers a session, no need to call those functions on their own. As far as it not working, do you have session_start() on the confirmation page as well, as the session_start() call will need to be made on any page you plan on accessing session variables. Link to comment https://forums.phpfreaks.com/topic/192469-session-problems/#findComment-1014131 Share on other sites More sharing options...
nblackwood Posted February 18, 2010 Author Share Posted February 18, 2010 Thanks for the response. I was under the impression that doing it that way can confuse session data if there's multiple users filling out the same form. Link to comment https://forums.phpfreaks.com/topic/192469-session-problems/#findComment-1014132 Share on other sites More sharing options...
nblackwood Posted February 18, 2010 Author Share Posted February 18, 2010 I tried as u suggested and put session_start(); on each page I need to access the data, but its still not working Link to comment https://forums.phpfreaks.com/topic/192469-session-problems/#findComment-1014135 Share on other sites More sharing options...
teamatomic Posted February 18, 2010 Share Posted February 18, 2010 You start a session and then initiate a session var and never set a value to it. How can you expect it to output anything? session_start(); $_SESSION["Name"]; You need something like session_start(); $_SESSION['Name'] = 'Teamatomic'; Then in a following page you can again start a session the echo out the $_SESSION['Name'] value, which will then echo out "Teamatomic". session_start(); $Name=$_SESSION['Name']; echo "$Name"; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/192469-session-problems/#findComment-1014137 Share on other sites More sharing options...
nblackwood Posted February 18, 2010 Author Share Posted February 18, 2010 Thanks, that worked. But how do I set it to echo a dynamic form field? Link to comment https://forums.phpfreaks.com/topic/192469-session-problems/#findComment-1014142 Share on other sites More sharing options...
teamatomic Posted February 18, 2010 Share Posted February 18, 2010 $Name=$_POST['Name']; $Name=strip_tags($Name); if(!magic_quote_gpc()){$Name=addslashes($Name);} $_SESSION['Name']=$Name; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/192469-session-problems/#findComment-1014144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.