<?php
// require session class
require_once('session.class.php');
// require mySQL handler class
// who can be downloaded from here: http://www.phpclasses.org/browse/package/2847.html
require_once('sql.class.php');
// set database values
$_DBHOST = 'localhost';
$_DBUSER = 'root';
$_DBNAME = 'test';
$_DBPASS = '';
// we will need this sql class
$s = new sql();
// 'start' the class
$c = new session($host); // host for the cookies (default: null)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// setting session values
// @note: when we use setVal()
// we update 'varname' if it exist or
// add it if it not exist
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// we can set value one by one
$c->setVal('varname1', 'value1');
$c->setVal('varname2', 'value2');
$c->setVal('varname3', 'value3');
$c->setVal('varname4', 'value4');
$c->setVal('varname5', 'value5');
// or we can set multiple values at once
$c->setVal(array(
'varname1' => 'value1',
'varname2' => 'value2',
'varname3' => 'value3',
'varname4' => 'value4',
'varname5' => 'value5'
));
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// getting values
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// check if value was set
if ($c->isVal('varname1'))
{
print 'varname1 exists ';
}
else
{
print 'varname1 do not exists ';
}
print '<br />';
// we can get values from $c->variables array
print $c->variables['varname2'];
print '<br />';
// or by $c->getVal() function
print $c->getVal('varname2');
print '<br />';
// or just cut the value(this will get it value and then delete it)
print $c->cutVal('varname2');
print '<br />';
// count all active sessions for the past 240 seconds
print 'active sessions: ' . $c->count(0, 240);
print '<br />';
// count all active session with assigned value 'varname5'
print 'activer sessions with \'varname5\': ' . $c->count('varname5', 240);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// deleting values
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// we can delete one particular value
$c->delVal('varname1');
// or delete a list of values
$c->delVal('varname2', 'varname3', 'varname4');
// or detete all sesssion value
$c->delVal();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// 'no expire' sessions
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// set current session as 'no expire' or endless session
$c->setNoExpire();
// check if current session is 'no expire'
if ($c->isNoExpire())
{
print 'this session is endless';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// stop session
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$c->endSession();
?>
|