Session problem

I am using sessions on a web site I’ve been working with for quite some time, but when testing some of the pages, I’m having problems with the sessions that I use from page to page to store some information.
All of a sudden I think I read a tip from someone telling me that sessions are not really working anymore in newer versions of php, is that right?

Then, what is the solution to make it work, when I have my page on a hosting server that is probably updated to the latest version.
I use things like these in my pages:


$_SESSION['username'] = $username;

What do I need to change to make it work? Or is it an easier way to change something globally?

Can you post the article that tells you session doesn’t work anymore on newer versions of php?

By the way are you using php alone or are you using a php framework?

I don’t have an article. I just thought I read something about it a couple of months ago. And I’ve had some problems with sessions lately. Just working with php.
Maybe it’s something else in my script that is causing the problem. I just woke up this morning and thought I heard something about it… but I might be wrong?

I have the exact same problem. I just changed my host server from PHP 5.2.17 to PHP 5.4.2 and now sessions don’t work. I can’t log in to my own site.
I know the reason why, session_register is depreciated in PHP 5.4+, but I don’t know the new way to set sessions.
Does anyone know?

You don’t need to use session_register any more, you can just do this:


That’s what I thought, but after commenting out the session_registers my login still doesn’t work.
I changed the login script to echo the sessions, to check they are there, and they were.
But, they are not available to other pages it seems.
After login you are redirected to the homepage, it (and the other pages) start with a login check that looks at the session data. The page displays differently if you are logged in, and it’s displaying like I’m not. If I try make the homepage echo the sessions, it doesn’t show.

The sessions appear on the page they are created, but not on any other page. To simplify things I made a very simple test script, rather than having to look at the whole login script.
This is page 1

$sessvalue = "This Text";
    <title>Session Test Set</title>
    <h1>Session Test Set</h1>
    <p>This should set the session.</p>
    <p>Session ID is: <?php echo $_SESSION['id']; ?></p>
    <p>Session value is: <?php echo $_SESSION['ses']; ?></p>
    <p><a href="session2.php">Link to next page.</a></p>

When I view this page it displays the session info.
The link goes to this page:

    <title>Session Test Read</title>
    <h1>Session Test Read</h1>
    <p>This should read the session.</p>
    <p>Session ID is: <?php echo $id; ?></p>
    <p>Session value is: <?php echo $sessvalue; ?></p>
    <p><a href="session1.php">Link to other page.</a></p>

When I click the link to go to this page, I don’t see any of the session data.
What am I doing wrong?

:blush:OK, forgive my stupidity.
I just added session_start() to the first script and it now works.
I did the same with my login script and that works too now.
It’s just that they did not need that with the old PHP that used session_register(), so I never thought to add it.