Codice PHP:
class session
{
var $sessionid = "";
var $sessionmemberid ="";
var $useragent = "";
var $ipaddress = "";
var $dateline = "";
var $islogged = false;
var $sessiontype = "";
var $sesstype = "";
var $SESS = array();
function session()
{
global $dbcore , $smarty , $RCW , $cookie , $techaut , $settings;
$this->sessiontype = $this->sesstype ;
$this->sessionid = session_id();
$this->sessionid = $cookie->GetCookie('adminid');
$this->ipaddress = $_SERVER['REMOTE_ADDR'];
$this->useragent = trim(substr($_SERVER['HTTP_USER_AGENT'], 0, 60));
}
function SessionStart($sesstype)
{
if(session_id()== "")
session_start();
global $dbcore , $smarty , $RCW , $cookie , $techaut , $settings;
$this->sessiontype = $sesstype ;
$this->sessionid = session_id();
$this->sessionmemberid = $cookie->GetCookie('adminid');
$this->ip_address = $_SERVER['REMOTE_ADDR'];
$this->useragent = trim(substr($_SERVER['HTTP_USER_AGENT'], 0, 60));
if($this->sessiontype === SESSION_ADMIN){
$sesstype = $this->sessiontype;
} else if($this->sessiontype === SESSION_STAFF){
$sesstype = $this->sessiontype;
} else if($this->sessiontype === SESSION_USER){
$sesstype = $this->sessiontype;
} else if($this->sessiontype === SESSION_GUEST){
$sesstype = $this->sessiontype;
} else {
return false;
}
if(!empty($_POST['sessionid']))
{
$sessionid = $_POST['sessionid'];
}else if (!empty($_GET['sessionid']))
{
$sessionid = $_GET['sessionid'];
}
else if(defined("SESSIONEXPIRY"))
{
echo "[Session Expired Debug]: Unable to find session id in POST, GET or COOKIE variable.. Clearing Out...";
}else{
/* return false; */
}
$sessionid = $this->sessionid ;
if($sessionid)
{
$this->readsess($sessionid);
}
}
function readsess($sessionid)
{
global $dbcore , $smarty , $RCW , $cookie , $techaut , $settings;
$result = $dbcore->querycount("SELECT * FROM `sessions` WHERE `sessionid` = '".$dbcore->escape($sessionid)."'") ;
if($result >0)
{
echo 'la sessione e presente';
} else {
$this->writesess($sessionid, $this->sessiontype) ;
}
}
function writesess($sessionid, $sesstype)
{
global $dbcore , $smarty , $RCW , $cookie , $techaut , $settings;
$res = $dbcore->query("REPLACE INTO `sessions`
(`sessionid`, `ipaddress`, `lastactivity`, `useragent`, `isloggedin`, `sessiontype`, `typeid`, `date`, `status`) VALUES(
'".$dbcore->escape($sessionid)."',
'".$dbcore->escape($this->ipaddress)."',
'". time()."',
'". $dbcore->escape(substr($this->useragent, 0,60))."',
'',
'". $dbcore->escape($this->sessiontype) ."',
'',
'". time() ."', 0)") or die(mysql_error());
if(!$res)
{
echo 'la sessione non e stata salvata ';
} else {
echo 'this session added '.$sessionid;
}
}
}