I have a piece of code below where it contains $_SESSION variables:
if (isset($_POST['id'])) {
$_SESSION['id'] = $_POST['id'];
}
if(isset($_SESSION['sessionNum'])){
//Declare my counter for the first time
$_SESSION['initial_session'] = $_SESSION['sessionNum'];
$_SESSION['sessionNumber'] = intval($_SESSION['sessionNum']);
$_SESSION['sessionCounting'] = 1;
}
…
ASSESSMENT: (<?php echo $assessment ?>) TOTAL ASSESSMENTS: <?php echo $_SESSION['initial_session'] ?>
The above statement displays this:
ASSESMENT: (WESSF) TOTAL ASSESSMENTS: 2
But two pages down the line (completesession.php) I want to use couple of those $_SESSION variables. Problem though is that if I do a var_dump($_SESSION['sessionNum']) then it only int(1) but not the value 2. Yet it does output (WESSF) for var_dump($_SESSION['id']). Why is this?
Below is the completesession.php) page:
<?php
ini_set('session.gc_maxlifetime',12*60*60);
ini_set('session.gc_divisor', '1');
ini_set('session.gc_probability', '1');
ini_set('session.cookie_lifetime', '0');
require_once 'init.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
var_dump($_SESSION['id']);
var_dump($_SESSION['sessionNum']);
?>
You might be looking in the wrong session key here. Use:
to display all sessions keys.
Also the code you’ve posted is not counting up any number, so the number
1looks correct (with the few I can see), and2would not be correct.A final note: Because you can successfully see
int(1)it shows that the session feature in your PHP setup is actually working. So you might have just made some mistake somewhere to set the correct key/value.