Jump to content

$_SESSION returns empty on other pages


v4g

Recommended Posts

Hello,

I use $_SESSION['rand_code'] variable in order to pass the image validator info to the page where the form is and compare it with the data the user submits. The problem is that $_SESSION var arrives empty.

// [b]form.php[/b] (submits to itself to check)
session_name('name');
session_start();
.....[b] // if i echo $_SESSION['rand_code'] here even after the form has submited and the image was created, it's null[/b]
if (!isset($_POST['validator']) || ($_POST['validator'] != $_SESSION['rand_code']))  //$_POST['validator']: form text field data
{
  <error flag and echo form> 
  ...
  <img src='random.php' alt='validator' width='60' height='20' vspace='1' align='top'>)
  ...
}
else {
  <do database stuff>
}


....


// [b]random.php[/b]
session_name('name');
session_start();
...
$_SESSION['rand_code']= <the random number of the image>
..

Its strange because this script used to work until recently. The only change that I did was to turn registers global off.
My [b]php.ini[/b] is:
register_globals = Off
session.cookie_lifetime = 1

[Zend]
zend_optimizer.optimization_level=15
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-2.5.10
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-2.5.10
zend_optimizer.version=2.5.10a
zend_extension = /usr/local/lib/ioncube_loader_lin_4.4.so
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so


Please help, thanks for reading.
Link to comment
https://forums.phpfreaks.com/topic/32847-_session-returns-empty-on-other-pages/
Share on other sites

The amount of your code that you posted does not give enough information about what might be going on (you won't believe the number of times on Forums where some code was left out as being irrelevant to the problem which was actually where the problem was.)

Since you are already using $_SESSION variables, changing register_globals should have had no effect on the function of sessions, but it may have had an effect on other code involved (such as generating the random value and setting the session variable.) We cannot tell this until we can see the actual code.

Also, add the following line after your first opening <?php tag -
[code]error_reporting(E_ALL);[/code]
  • 2 weeks later...
I'm having this same problem. My register_globals is set to On.
I am setting a session variable and if I echo it immediately it works fine. If I try to echo it on another page it doesn't display anything.

code:
session_start();
$_SESSION['var1'] = 123;
$_SESSION['var2'] = 456;
print_r($_SESSION);

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.