473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

$_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 1894
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.com
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******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Dec 22 '05 #3

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

Similar topics

0
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...
4
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...
0
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...
21
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...
12
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...
4
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...
2
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...
4
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...
3
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 =...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.