473,661 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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=FAIL ED". 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 1814
mwasif
802 Recognized Expert Contributor
What version of PHP you are using? I hope you are working with register_global s enabled.
Jun 22 '07 #2
pbmods
5,821 Recognized Expert Expert
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_global s enabled.
You mean that you hope that register_global s is enabled because that would explain the problem, right? 'Cause I can't think of any reason why anybody would actually WANT register_global s enabled (it's actually going away in PHP 6)!
Jun 22 '07 #3

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

Similar topics

5
10900
by: Rob Tweed | last post by:
Probably a simple question but I can't find the answer anyway. Specifically, is it possible to copy a multidimensional array into the $_SESSION array - ie a deep clone of all keys and data? I naively assumed that $_SESSION = $myArray ; would work but it doesn't appear to work. Is there a single function
13
23313
by: Mimi | last post by:
Hello, I am having trouble using the session vars in PHP 4.3.9 OS: Win XP Prof Web Server IIS (is local and there are no links to other servers from the web pages I work on) Browser: IE 6.0 The problem I am having is that each time I reload the same PHP page, I get
4
3096
by: Tom | last post by:
A small problem that has me kinda baffled. This is the situation: I've set up a self-submitting form FORM.PHP. Once the inputs are validated, the info gets put in SESSION variables and the script redirects the user to a review form REVIEW.PHP which displays the info the user has input and allows them to edit or submit. At the top of that page, I have the following code: --- start code ---
5
2128
by: James Baker | last post by:
I have a form that has a dropdown list that will cause a post to the same page when it's changed. The problem I'm running into is that all of the controls reset to their default values (obviously expected behavior). What's the recommended/best way to persist these values through the post process? I know I could set them to the request.form values of themselves, so to speak...but I didn't know if there was a simpler/more efficient way. ...
18
7822
by: Dan Cernat | last post by:
Hi there, A few threads I had a little chat about default values. I am starting this thread because I want to hear more opinions about the default values of function parameters. Some say they see no use of them. Others say thar they are bad. I like them. So, could anyone tell me why they are in the standard? Are they bad? I do not intend to start war. Nor am I a troll.
6
4363
by: Neil | last post by:
Hi, I have an aspx page with a number of web controls on it and one of these is a cancel button. I want to check the page to see if the user has changed any of the controls, i..e typed some text in a textbox, changed a dropdown etc The reason I want to do this is when the user clicks cancel I want to notify them that their changes will be lost using a popup or something. My question is what is the best way to compare the page that...
21
3053
by: axlq | last post by:
Someone please tell me if I've discovered a PHP bug. I'm sitting in front of several computers on my home network, behind a NAT firewall/router. I am testing my web site on these different computers (running different browsers, logged in as different users, etc.). My web site keeps track of users logged in through the use of $_SESSION. Here's the bizarre thing: All computers are logged off, then I log into my web site with one...
4
2134
by: Daz | last post by:
Hi everyone. I'm just wondering if it's considered bad practice to have a class read from and write to the $_SESSION super global. I was just learning a little about object serialization, and I've come to the conclusion that storing potentially large serialized objects in a database is perhaps a bad idea. The data could also be stored in a file, but in that case, I may as well use $_SESSION. If I'm going to go down that road, why not store...
4
1808
TheServant
by: TheServant | last post by:
Hi guys, This is my situation. I have 3 sets of data used on every page of my website. Two of these never change, and the reason they are stored in MySQL and recalled into the $_SESSION variable is simply because I want to have one place to update/change them if I ever need to. What I have been wondering is if I should leave the user specific variables in the session, and define the other variables in another file/array which is called on...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.