1

I'm sure that my question does come from not understanding an very basic mechanic, yet I spend hours already and I'm still unable to solve the problem.

I made two test files: test1.php:

//as you can see I did some research, yet it looks that my session save path is fine, so this is not the case
if (is_writable(session_save_path()))
    echo 'ok <br />';

$_SESSION['test'] = '!!!single!!!'; //this saves and stays in the $_SESSION
$_SESSION[1]['test'] = '???multi???'; //this dissapears - but why and how to prevent this?

print_r($_SESSION);
?>

Outcome:

ok Array ( [test] => !!!single!!! [1] => Array ( [test] => ???multi??? ) )

Exactly as expected.

test2.php:

if (is_writable(session_save_path()))
    echo 'ok <br />'; //just to be sure

print_r($_SESSION); //why, oh why?
?>

Outcome:

ok Array ( [test] => !!!single!!! )

And my "[1] => Array ( [test] => ???multi??? )" is not there... But why? The superglobal $_SESSION was set as above, nothing was changed...

My server does have register_globals set to off - well, could this be the case? Even if - I don't want to turn it on just like that. It seems like wrong thing to do anyway.

Many thanks in advance, best regards!

Zorann
  • 335
  • 2
  • 16
  • You can instead make `$_SESSION['test']` an array instead of $_SESSION itself. `$_SESSION['test'][] = 'foo'; $_SESSION['test'][] = 'bar';` – Ikhlak S. Oct 19 '18 at 09:58

0 Answers0