471,066 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

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

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
2 1719
mwasif
802 Expert 512MB
What version of PHP you are using? I hope you are working with register_globals enabled.
Jun 22 '07 #2
pbmods
5,821 Expert 4TB
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.

Similar topics

5 posts views Thread by Rob Tweed | last post: by
4 posts views Thread by Tom | last post: by
5 posts views Thread by James Baker | last post: by
18 posts views Thread by Dan Cernat | last post: by
4 posts views Thread by Daz | last post: by
TheServant
4 posts views Thread by TheServant | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.