468,315 Members | 1,404 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

variables that change session variables

Hi, I'm currently writing a mulit-page form app that uses a session to
retain data from each form element in order for the user to jump
between pages, then the final data is passed to a calculation script.

However, I've noticed that if I assign a session variable to another
variable, which then performs a mathematical calculation, the session
variable changes.

i.e. $_SESSION["inflation"] = 4;
$temp_inf = $_SESSION["inflation"];
if ($_SESSION["inflation"] =="RPI") {
$inflation = $rpi;}
else {$inflation = ($temp_inf/100.0);}
now it equals = 0.04

How can I take a value from a session and perform operations on it
without altering the original session value.
Rgds
Neil.
Jul 16 '05 #1
1 6364
sentinel wrote:
However, I've noticed that if I assign a session variable to another
variable, which then performs a mathematical calculation, the session
variable changes.

i.e. $_SESSION["inflation"] = 4;
$temp_inf = $_SESSION["inflation"];
if ($_SESSION["inflation"] =="RPI") {
$inflation = $rpi;}
else {$inflation = ($temp_inf/100.0);}
now it equals = 0.04

How can I take a value from a session and perform operations on it
without altering the original session value.


This happends because you have the register_globals directive turned on
and thus, $_SESSION['inflation'] and $inflation contain the same value
and if you manipulate one the other changes as well.

There's two solutions to your problem, either change your naming (i.e.
switch from $_SESSION['inflation'] to $_SESSION['foo'] or from
$inflation to $bar) or turn register_globals off.
Per Gustafsson

--
http://www.pergustafsson.com/
Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Microsoft | last post: by
14 posts views Thread by Paul Yanzick | last post: by
31 posts views Thread by Harry Simpson | last post: by
3 posts views Thread by bennett | last post: by
7 posts views Thread by Erik | last post: by
26 posts views Thread by BillE | last post: by
5 posts views Thread by dougloj | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.