473,666 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

$_SESSION issue

Tom
I put together a code that checks for 2 post variables then stores them
in a multi-dim $_SESSION array, something like this:

If ( isset($_POST['value_a'] && isset($_POST['value_b']) )
{
$_SESSION['value']['a'] = $_POST['value_a'];
$_SESSION['value']['b'] = $_POST['value_b'];
}

The problem was that $_SESSION['value']['b'] was being overwritten with
the value for 'a' so that both $_SESSION['value'] vars ended up being
the same (i.e. $_POST['value_b']. I thoroughly tested it to confirm
that this was what happening.

I solved the problem by changing the $_SESSION vars to
$_SESSION['value_a'] and $_SESSION['value_b'].

This was PHP 5, the WAMP package -- I know it's not the latest update
of PHP 5.

My question: is this a bug (perhaps since fixed) or is there a reason
this would be expected behavior?

Thanks,

Tom
http://phosphorusandlime.blogspot.com/

Dec 21 '05 #1
2 1911
Tom wrote:
I put together a code that checks for 2 post variables then stores them
in a multi-dim $_SESSION array, something like this:

If ( isset($_POST['value_a'] && isset($_POST['value_b']) )
{
$_SESSION['value']['a'] = $_POST['value_a'];
$_SESSION['value']['b'] = $_POST['value_b'];
}

The problem was that $_SESSION['value']['b'] was being overwritten with
the value for 'a' so that both $_SESSION['value'] vars ended up being
the same (i.e. $_POST['value_b']. I thoroughly tested it to confirm
that this was what happening.

I solved the problem by changing the $_SESSION vars to
$_SESSION['value_a'] and $_SESSION['value_b'].

This was PHP 5, the WAMP package -- I know it's not the latest update
of PHP 5.

My question: is this a bug (perhaps since fixed) or is there a reason
this would be expected behavior?


The only way that I forsee this being expected behavior is if
$_POST['value_a'] == $_POST['value_b']

Usually when I am assigning an array to a session key, I will use:

$_SESSION['key'] = array('a'=>$a, 'b'=>$b);

I have never had any problems using either method, and tested that on my
two 5.1.1 installs which worked fine.

--
Justin Koivisto, ZCE - ju****@koivi.co m
http://koivi.com
Dec 21 '05 #2
Following on from Tom's message. . .
I put together a code that checks for 2 post variables then stores them
in a multi-dim $_SESSION array, something like this:

If ( isset($_POST['value_a'] && isset($_POST['value_b']) )
{
$_SESSION['value']['a'] = $_POST['value_a'];
$_SESSION['value']['b'] = $_POST['value_b'];
}

The problem was that $_SESSION['value']['b'] was being overwritten with
the value for 'a' so that both $_SESSION['value'] vars ended up being
the same (i.e. $_POST['value_b']. I thoroughly tested it to confirm
that this was what happening.


The following code works 'as advertised':
<?php
$SES['value']['a'] = 'va';
$SES['value']['b'] = 'vb';
print_r($SES);
?>
to give
Array ( [value] => Array ( [a] => va [b] => vb ) )

It works with $_SESSION too.

Are you operating in a foreach loop? If so this is a Gotcha.

Although not particularly related to this problem but in a similar vein:
Look up "variable variables" in the manual.

// convert $ay['foo'] into $foo
foreach($ay as $key => $val) {$$key = $ay[$key];}


--
PETER FOX Not the same since the bookshop idea was shelved
pe******@eminen t.demon.co.uk.n ot.this.bit.no. html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.dem on.co.uk>
Dec 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1867
by: Taz | last post by:
comp.lang.php, I have recently launched the new Planet-Tolkien.com, one would think that writing a message board from scratch and a dynamic weather system, a simple session login would be the least of my problems right? Wrong. It would appear that for Mozilla and Opera keep a $_SESSION is not an issue and the $_SESSION is continued until the member logs out. However when members are using Internet Explorer browser (most
4
12294
by: tornado | last post by:
Hello all, I am not able to find the solution to this problem :(. I have two php pages . On the first page i am getting some values in $_SESSION when i use print_r function. I don't get the values when i use just echo() or print() functions. Now, the first page calls the second php page. But when i try to get the values for $_SESSION on the second page i get empty values even when i use print_r() function. register.globals is set...
0
2478
by: Phil Powell | last post by:
What is the most standardized method of utilizing the CURL functions in PHP (version 4.3.2) to be able to retrieve the contents of a remote URL that happens to be dependent upon $_SESSION for its content display? I've tried the following class methods for display and I have most everything working until I get to a URL that requires $_SESSION: class Timer extends View {
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...
12
41161
by: Michael Windsor | last post by:
I've been trying to integrate some PHP pages of my own with some existing code. The details of this are for the support forums for that code (where I have been asking questions), but I wonder if someone here can enlighten me as to why the problematic code is having the effect it is. For reasons I don't know, if the PHP version is 5 or greater, register_long_arrays is false and $_SESSION exists, the following statement is executed: ...
4
2047
by: Pseudonyme | last post by:
Dear Sirs and Madams, Receive as information that storing a MYSQL result under $_SESSION was accelerating web page displays processes ? Absolutly needed but impossible to get this working ! I try, but do not succeed in implement $_SESSION with MYSQL. <?php session_start();
2
2263
by: sharonDonnelly | last post by:
Hi Really dumb problem that's got me beat. Can someone help. The prolem: I'm trying to count the number of times an item has been clicked. There are many items. I want to create a session variable for each item as its clicked, and increment the value held by the session variable by 1 each time that item is clicked. My plan was to allow an item to be selected on one page - when a user selects an item, a numeric value will be passed to a...
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...
3
2176
by: JRough | last post by:
I want to save two variables in a $_SESSION for use in another page: $_SESSION = $mark; $_SESSION = $num; then on the other page I did this to get the value: $mark =$_SESSION; $num = $_SESSION;
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
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
8863
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...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
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
7378
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
2765
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
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.