read/write Session Variables from a class
Posted: Wed Aug 08, 2012 10:41 am
I have created a class to handle some Debugging code, but I am stuck at how to make it read / write to a Session Variable.
I have a $Counter variable that normally holds an incrementing Page Counter, which is then stored to a SESSION Variable between page loads.
But I can't see how to do it in a class. I was thinking something like:
but it doesn't work, what is the correct way to read / write Session variables from classes?
I have a $Counter variable that normally holds an incrementing Page Counter, which is then stored to a SESSION Variable between page loads.
But I can't see how to do it in a class. I was thinking something like:
Code: Select all
class pgCounter
{
var $timezone;
var $date;
var $DebugDate;
var $ResetTime;
var $Counter;
function __construct()
{
$this->timezone = "Europe/London";
date_default_timezone_set ($this->timezone);
$this->date = date('H:i:s');
}
function Counter()
{
echo $this->date;
if(isset($_SESSION['Counter']))
{
$Counter = $_SESSION['Counter'];
}
else
{
$Counter = 1;
};
$_SESSION['Counter'] = $Counter;
echo "Count - $this.Counter;
$this->Counter++;
$_SESSION['Counter'] = $this->Counter;
}
}