Session variables keep resetting
Posted: Wed Apr 01, 2009 3:00 pm
Hello,
I have started a session in index.php, which allows the variables to be used in basket.php
I add 1 to the variable in basket.php but when loading the index.php the variable gets reset.
I have tried to say only reset variables when there is no session id, although this seems to fail. How do I initialise variables at the start of a session and ensure they are not reset as the variables are changes as they are used throughout the other pages.
The code below is in index.php
This code is in basket.php
Thanks
I have started a session in index.php, which allows the variables to be used in basket.php
I add 1 to the variable in basket.php but when loading the index.php the variable gets reset.
I have tried to say only reset variables when there is no session id, although this seems to fail. How do I initialise variables at the start of a session and ensure they are not reset as the variables are changes as they are used throughout the other pages.
The code below is in index.php
Code: Select all
if(session_id()==0){
$carttest[] = array(30);
$_SESSION["carttest"] = $carttest;
$pointer = 0;
$_SESSION["pointer"] = $pointer;
}This code is in basket.php
Code: Select all
$newpointer = $_SESSION['pointer'];
$receivecartid = $_SESSION['carttest'];
$receivecartid[$newpointer] = $_POST['album_id'];
$newpointer = $newpointer +1;
$_SESSION['pointer'] = $newpointer;