Jump to content

Session Problems


nblackwood

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.