Jump to content

Sessions don't work


turbo

Recommended Posts

  With PHP 5 the default setting for register globals is off. This means that sessions variables don't work (see quote below).

 

So, I have a website that makes plenty of use of sessions, which has stopped working properly. The question is, what changes do i have to make to ensure I can still make use of them or something similar to them? Thanks

 

"If you want your script to work regardless of register_globals,

    you need to instead use the $_SESSION array as $_SESSION entries

    are automatically registered. If your script uses session_register(),

    it will not work in environments where the PHP directive

    register_globals  is disabled."

Link to comment
https://forums.phpfreaks.com/topic/43154-sessions-dont-work/
Share on other sites

Sessions work fine. What you don't want to use is the "session_register()" function.  You explicitly set the session variables using

<?php
session_start();
$_SESSION['somevar'] = $some_var;
$_SESSION['anothervalue'] = 'This will be stored';
?>

and you get the stored values explicitly also:

<?php
session_start();
echo '$somevar in the Session is: ' . $_SESSION['somevar'];
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/43154-sessions-dont-work/#findComment-209554
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.