Schmoopy
02-03-2009, 12:37 AM
Ok, I've just started looking into sessions and was messing around with simple stuff, like incrementing the user's session value every time they requested the page, but I came across the following problem:
I was trying to do the following
session_start();
session_register('counter');
$counter = $_SESSION['counter'];
// Try incrementing $counter now that it points to the session variable
$counter++;
echo $counter;
It quickly became apparent that the value of the counter only reflected the value of the session variable, meaning I can't increment the counter variable.
The way to do it would be:
$_SESSION['counter']++;
So I was just wondering if there was a way of transferring the value to the $counter variable, instead of merely reflecting what is held in the session.
In its current state I can only echo the $counter, but I can't add anything to it, or perform any operations on it.
Any way to get around this?
Thanks,
Jack.
I was trying to do the following
session_start();
session_register('counter');
$counter = $_SESSION['counter'];
// Try incrementing $counter now that it points to the session variable
$counter++;
echo $counter;
It quickly became apparent that the value of the counter only reflected the value of the session variable, meaning I can't increment the counter variable.
The way to do it would be:
$_SESSION['counter']++;
So I was just wondering if there was a way of transferring the value to the $counter variable, instead of merely reflecting what is held in the session.
In its current state I can only echo the $counter, but I can't add anything to it, or perform any operations on it.
Any way to get around this?
Thanks,
Jack.