SessionTimeout = $this->Application->ConfigValue('SessionTimeout'); $path = (BASE_PATH == '') ? '/' : BASE_PATH; if ( $this->Application->IsAdmin() ) $path = rtrim($path, '/').'/admin'; $this->SetCookiePath($path); $cookie_name = $this->Application->ConfigValue('SessionCookieName'); $this->SetCookieName($cookie_name ? $cookie_name : 'sid'); $this->SetCookieDomain(SERVER_NAME); if( $this->Application->IsAdmin() ) { $mode = constOn('IS_INSTALL') ? smCOOKIES_ONLY : smAUTO; } else { $ses_mode = $this->Application->ConfigValue('CookieSessions'); if ($ses_mode == 2) $mode = smAUTO; if ($ses_mode == 1) $mode = smCOOKIES_ONLY; if ($ses_mode == 0) $mode = smGET_ONLY; } $this->SetMode($mode); parent::Init($prefix,$special); if( !$this->Application->IsAdmin() && $this->GetField('PortalUserId') <= 0 ) { $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup'); $this->SetField('GroupList', $group_list); } } } class InpSessionStorage extends SessionStorage { function Init($prefix,$special) { parent::Init($prefix,$special); $this->setTableName(TABLE_PREFIX.'UserSession'); $this->SessionDataTable = TABLE_PREFIX.'SessionData'; $this->setIDField('SessionKey'); $this->TimestampField = 'LastAccessed'; $this->DataValueField = 'VariableValue'; $this->DataVarField = 'VariableName'; } function LocateSession($sid) { $query = ' SELECT '.$this->TimestampField.' FROM '.$this->TableName.' WHERE '.$this->IDField.' = '.$this->Conn->qstr($sid); $result = $this->Conn->GetOne($query); if($result===false) return false; $this->Expiration = $result + $this->SessionTimeout; return true; } function UpdateSession(&$session) { $query = ' UPDATE '.$this->TableName.' SET '.$this->TimestampField.' = unix_timestamp() WHERE '.$this->IDField.' = '.$this->Conn->qstr($session->SID); $this->Conn->Query($query); } function StoreSession(&$session) { parent::StoreSession($session); $this->SetField($session, 'IpAddress', $_SERVER['REMOTE_ADDR']); $this->SetField($session, 'GroupList', $this->Application->ConfigValue('User_GuestGroup')); } function GetExpiredSIDs() { $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.adodb_mktime().' - '.$this->TimestampField.' > '.$this->SessionTimeout; $ret = $this->Conn->GetCol($query); if($ret) { $this->DeleteEditTables(); } return $ret; } function DeleteEditTables() { $tables = $this->Conn->GetCol('SHOW TABLES'); $mask_edit_table = '/'.TABLE_PREFIX.'ses_(.*)_edit_(.*)/'; $mask_search_table = '/'.TABLE_PREFIX.'ses_(.*?)_(.*)/'; $sql='SELECT COUNT(*) FROM '.$this->TableName.' WHERE '.$this->IDField.' = \'%s\''; foreach($tables as $table) { if( preg_match($mask_edit_table,$table,$rets) || preg_match($mask_search_table,$table,$rets) ) { $sid=$rets[1]; $is_alive = $this->Conn->GetOne( sprintf($sql,$sid) ); if(!$is_alive) $this->Conn->Query('DROP TABLE IF EXISTS '.$table); } } } } ?>