By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,570 Members | 1,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,570 IT Pros & Developers. It's quick & easy.

$_SESSION values changed... but I didn't change them!

P: 1
Take the following code, one would think that there was absolutely no link between $test and $_SESSION["test"]. But if you reload the page, guess what... "After=FAILED". Why? Because for some reason, writing to $test affects the $_SESSION variable $_SESSION["test"].
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. ini_set("session.gc_maxlifetime","3600");
  3. if ($_REQUEST["it"] == "1") session_unset();
  4.  
  5. var_dump($_SESSION);
  6. if (!$_SESSION["test"]) $_SESSION["test"] = "Test";
  7. echo "Before=".$_SESSION["test"]."<br>";
  8. $test = "FAILED";
  9. echo "After=".$_SESSION["test"]."<br>";
  10. var_dump($_SESSION);
  11.  
  12.  
  13. After doing a var_dump($_SESSION), on the first go round I got:
  14. array(1) {
  15.   ["test"]=>
  16.   string(4) "Test"
  17. }
  18.  
  19. On the second go round I got:
  20. array(1) {
  21.   ["test"]=>
  22.   &string(4) "Test"
  23. }
  24.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

Apparently as soon as it starts storing by reference (with the "&") after reloading the page, that's when the troubles begin. That's as far as I can get in putting forth the problem. I have no idea how to fix it though. Either the "&string" needs to be disabled somehow in the session, or something needs to be disconnected so that writing to $test won't overwrite the value in $_SESSION["test"].

Any help on this one would be greatly appreciated. I've looked all over and no luck.
Jun 22 '07 #1
Share this Question
Share on Google+
2 Replies


mwasif
Expert 100+
P: 801
What version of PHP you are using? I hope you are working with register_globals enabled.
Jun 22 '07 #2

pbmods
Expert 5K+
P: 5,821
Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as 'need help' actually get FEWER responses?).

I hope you are working with register_globals enabled.
You mean that you hope that register_globals is enabled because that would explain the problem, right? 'Cause I can't think of any reason why anybody would actually WANT register_globals enabled (it's actually going away in PHP 6)!
Jun 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.