$_SESSION variables not carrying over to next pages?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Wed Mar 26, 2008 2:18 pm

So it is assuming that by the next page they are saying that the $_POST variables now equal ZERO. So it redoes the variable with the new post value of zero. Pretty lame to me. Functions do this to. SO variables are always changing even if a new variable is changed farther down the page. What I mean is if I say
$A = 2;
$B = $A
$A = 3;
echo $B;

it will spit out: 3

Well it actually spits out: 2

So WTF! Why do my variables seem to change?

$LowerYear = $today - $_POST[lesserage]; // equals the year so 2008 - 0 = 2008

$HigherYear = $today - $_POST[greaterage] - 1; // equals the year so 2008 - 22 = 1986

Mother F'er!!
When you do a $B = $A; it makes $B the value of $A there is no reference created so it's basically a copy of the variable. If you make changes to $A later those changes are not being assigned to $B. If you want it to actually spit out 3 you have to assign $A as a reference. $B =& $A; When you make a change to $A php will see that you made a reference and the value of $B will also be changed.

For the actual problem you are having I would need to see more code. $_POST variables are a one time variable and do not continue on the next page load. On the page you post to you could do something like $_SESSION['form'] = $_POST; and then you can access all the data in that posted form by $_SESSION['form']['formVariable']. Just remember that you would have do assign the post to the session variable every time you post otherwise you'll have old data from the previous post.

Post Reply