4 require_once(
'Services/Authentication/classes/class.ilSessionControl.php');
5 require_once(
'Services/Authentication/classes/class.ilSessionStatistics.php');
6 require_once(
'Services/Authentication/classes/class.ilSessionIStorage.php');
79 $q =
"SELECT data FROM usr_session WHERE session_id = " .
80 $ilDB->quote($a_session_id,
"text");
81 $set =
$ilDB->query($q);
82 $rec =
$ilDB->fetchAssoc($set);
85 return (
string) $rec[
"data"];
100 $query =
'SELECT expires FROM usr_session WHERE session_id = ' .
101 $ilDB->quote($a_session_id,
'text');
104 return (
int)
$row->expires;
120 $ilDB = $DIC[
'ilDB'];
121 $ilClientIniFile = $DIC[
'ilClientIniFile'];
123 if (self::isWebAccessWithoutSessionEnabled()) {
130 if (!$a_session_id) {
138 "user_id" => array(
"integer", (
int)
$_SESSION[
'_authsession_user_id']),
139 "expires" => array(
"integer", self::getExpireValue()),
140 "data" => array(
"clob", $a_data),
141 "ctime" => array(
"integer", $now),
142 "type" => array(
"integer", (
int) $_SESSION[
"SessionType"])
144 if ($ilClientIniFile->readVariable(
"session",
"save_ip")) {
145 $fields[
"remote_addr"] = array(
"text",
$_SERVER[
"REMOTE_ADDR"]);
151 if (class_exists(
"ilContext")) {
160 array(
"session_id" => array(
"text", $a_session_id))
163 $fields[
"session_id"] = array(
"text", $a_session_id);
164 $fields[
"createtime"] = array(
"integer", $now);
168 if (class_exists(
"ilContext")) {
172 $ilDB->insert(
"usr_session", $fields);
175 $type = $fields[
"type"][1];
178 $fields[
"session_id"][1],
180 $fields[
"createtime"][1],
181 $fields[
"user_id"][1]
187 $random = new \ilRandom();
188 if ($random->int(0, 50) == 2) {
190 self::_destroyExpiredSessions();
207 if (!$a_session_id) {
212 $ilDB = $DIC[
'ilDB'];
214 $q =
"SELECT 1 FROM usr_session WHERE session_id = " .
$ilDB->quote($a_session_id,
"text");
215 $set =
$ilDB->query($q);
217 return $ilDB->numRows($set) > 0;
227 public static function _destroy($a_session_id, $a_closing_context = null, $a_expired_at = null)
231 $ilDB = $DIC[
'ilDB'];
233 if (!$a_closing_context) {
234 $a_closing_context = self::$closing_context;
240 if (!is_array($a_session_id)) {
241 $q =
"DELETE FROM usr_session WHERE session_id = " .
242 $ilDB->quote($a_session_id,
"text");
246 $a_session_id = array_keys($a_session_id);
248 $q =
"DELETE FROM usr_session WHERE " .
249 $ilDB->in(
"session_id", $a_session_id,
"",
"text");
254 $ilDB->manipulate($q);
268 $ilDB = $DIC[
'ilDB'];
270 $q =
"DELETE FROM usr_session WHERE user_id = " .
271 $ilDB->quote($a_user_id,
"integer");
272 $ilDB->manipulate($q);
284 $ilDB = $DIC[
'ilDB'];
286 $q =
"SELECT session_id,expires FROM usr_session WHERE expires < " .
287 $ilDB->quote(time(),
"integer");
291 $ids[
$row[
"session_id"]] = $row[
"expires"];
294 self::_destroy($ids, self::SESSION_CLOSE_EXPIRE,
true);
310 $ilDB = $DIC[
'ilDB'];
313 $new_session = $a_session_id;
315 $new_session = md5($new_session);
316 $q =
"SELECT * FROM usr_session WHERE " .
317 "session_id = " .
$ilDB->quote($new_session,
"text");
321 $query =
"SELECT * FROM usr_session " .
322 "WHERE session_id = " .
$ilDB->quote($a_session_id,
"text");
348 return time() + self::getIdleValue($fixedMode);
352 if (
$ilSetting->get(
'session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED) {
353 return time() + self::getIdleValue($fixedMode);
354 } elseif (
$ilSetting->get(
'session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT) {
375 $ilClientIniFile = $DIC[
'ilClientIniFile'];
377 if ($fixedMode ||
$ilSetting->get(
'session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED) {
379 return $ilClientIniFile->readVariable(
'session',
'expire');
380 } elseif (
$ilSetting->get(
'session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT) {
397 return self::getIdleValue(
true);
410 $ilDB = $DIC[
'ilDB'];
412 $query =
"SELECT DISTINCT user_id FROM usr_session" 413 .
" WHERE remote_addr = " .
$ilDB->quote($a_ip,
"text")
414 .
" AND user_id > 0";
430 public static function set($a_var, $a_val)
441 public static function get($a_var)
452 public static function clear($a_var)
464 self::$closing_context = (int) $a_context;
474 return self::$closing_context;
484 return (
bool) self::$enable_web_access_without_session;
static _destroy($a_session_id, $a_closing_context=null, $a_expired_at=null)
Destroy session.
static enableWebAccessWithoutSession($enable_web_access_without_session)
const SESSION_CLOSE_CAPTCHA
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
const SESSION_CLOSE_INACTIVE
static $session_types_controlled
const SESSION_CLOSE_LOGIN
static isSessionMainContext()
Context that are not only temporary in a session (e.g.
const SESSION_HANDLING_FIXED
static _destroyExpiredSessions()
Destroy expired sessions.
const SESSION_CLOSE_EXPIRE
static getExpireValue($fixedMode=false)
Returns the expiration timestamp in seconds.
foreach($_POST as $key=> $value) $res
static _exists($a_session_id)
Check whether session exists.
static destroySession($a_session_id)
Destroy session(s).
static clear($a_var)
Unset a value.
static _getData($a_session_id)
Get session data from table.
static createRawEntry($a_session_id, $a_session_type, $a_timestamp, $a_user_id)
Create raw data entry.
static _destroyByUserId($a_user_id)
Destroy session.
static getIdleValue($fixedMode=false)
Returns the idle time in seconds.
static isWebAccessWithoutSessionEnabled()
const SESSION_CLOSE_LIMIT
static lookupExpireTime($a_session_id)
Lookup expire time for a specific session ilDB $ilDB.
static $enable_web_access_without_session
const SESSION_CLOSE_PUBLIC
const SESSION_CLOSE_SIMUL
static _writeData($a_session_id, $a_data)
Write session data.
static _duplicate($a_session_id)
Duplicate session.
static setClosingContext($a_context)
set closing context (for statistics)
const SESSION_HANDLING_LOAD_DEPENDENT
static _getUsersWithIp($a_ip)
Get the active users with a specific remote ip address.
static getType()
Get context type.
static getClosingContext()
get closing context (for statistics)
static getSessionExpireValue()
Returns the session expiration value.
static aggretateRaw($a_now)
Aggregate raw session data (older than given time)
const SESSION_CLOSE_FIRST
static closeRawEntry($a_session_id, $a_context=null, $a_expired_at=null)
Close raw data entry.