Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.