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');
77 $q =
"SELECT data FROM usr_session WHERE session_id = " .
78 $ilDB->quote($a_session_id,
"text");
79 $set = $ilDB->query($q);
80 $rec = $ilDB->fetchAssoc($set);
83 return (
string) $rec[
"data"];
96 $query =
'SELECT expires FROM usr_session WHERE session_id = ' .
97 $ilDB->quote($a_session_id,
'text');
100 return (
int)
$row->expires;
114 global
$ilDB, $ilClientIniFile;
116 if (self::isWebAccessWithoutSessionEnabled()) {
123 if (!$a_session_id) {
131 "user_id" =>
array(
"integer", (
int)
$_SESSION[
'_authsession_user_id']),
132 "expires" =>
array(
"integer", self::getExpireValue()),
133 "data" =>
array(
"clob", $a_data),
134 "ctime" =>
array(
"integer", $now),
135 "type" =>
array(
"integer", (
int) $_SESSION[
"SessionType"])
137 if ($ilClientIniFile->readVariable(
"session",
"save_ip")) {
138 $fields[
"remote_addr"] =
array(
"text",
$_SERVER[
"REMOTE_ADDR"]);
144 if (class_exists(
"ilContext")) {
153 array(
"session_id" =>
array(
"text", $a_session_id))
156 $fields[
"session_id"] =
array(
"text", $a_session_id);
157 $fields[
"createtime"] =
array(
"integer", $now);
161 if (class_exists(
"ilContext")) {
165 $ilDB->insert(
"usr_session", $fields);
168 $type = $fields[
"type"][1];
171 $fields[
"session_id"][1],
173 $fields[
"createtime"][1],
174 $fields[
"user_id"][1]
180 $random = new \ilRandom();
181 if ($random->int(0, 50) == 2) {
183 self::_destroyExpiredSessions();
200 if (!$a_session_id) {
205 $q =
"SELECT 1 FROM usr_session WHERE session_id = " . $ilDB->quote($a_session_id,
"text");
206 $set = $ilDB->query($q);
208 return $ilDB->numRows($set) > 0;
218 public static function _destroy($a_session_id, $a_closing_context = null, $a_expired_at = null)
222 if (!$a_closing_context) {
223 $a_closing_context = self::$closing_context;
229 if (!is_array($a_session_id)) {
230 $q =
"DELETE FROM usr_session WHERE session_id = " .
231 $ilDB->quote($a_session_id,
"text");
235 $a_session_id = array_keys($a_session_id);
237 $q =
"DELETE FROM usr_session WHERE " .
238 $ilDB->in(
"session_id", $a_session_id,
"",
"text");
243 $ilDB->manipulate($q);
257 $q =
"DELETE FROM usr_session WHERE user_id = " .
258 $ilDB->quote($a_user_id,
"integer");
259 $ilDB->manipulate($q);
271 $q =
"SELECT session_id,expires FROM usr_session WHERE expires < " .
272 $ilDB->quote(
time(),
"integer");
273 $res = $ilDB->query($q);
275 while (
$row = $ilDB->fetchAssoc(
$res)) {
276 $ids[
$row[
"session_id"]] = $row[
"expires"];
279 self::_destroy($ids, self::SESSION_CLOSE_EXPIRE,
true);
296 $new_session = $a_session_id;
298 $new_session = md5($new_session);
299 $q =
"SELECT * FROM usr_session WHERE " .
300 "session_id = " . $ilDB->quote($new_session,
"text");
301 $res = $ilDB->query($q);
302 }
while ($ilDB->fetchAssoc(
$res));
304 $query =
"SELECT * FROM usr_session " .
305 "WHERE session_id = " . $ilDB->quote($a_session_id,
"text");
308 while (
$row = $ilDB->fetchObject(
$res)) {
329 if ($fixedMode || $ilSetting->get(
'session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED) {
331 return time() + self::getIdleValue($fixedMode);
332 } elseif ($ilSetting->get(
'session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT) {
352 if ($fixedMode || $ilSetting->get(
'session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED) {
354 return $ilClientIniFile->readVariable(
'session',
'expire');
355 } elseif ($ilSetting->get(
'session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT) {
372 return self::getIdleValue(
true);
385 $query =
"SELECT DISTINCT user_id FROM usr_session" 386 .
" WHERE remote_addr = " . $ilDB->quote($a_ip,
"text")
387 .
" AND user_id > 0";
403 public static function set($a_var, $a_val)
414 public static function get($a_var)
425 public static function clear($a_var)
437 self::$closing_context = (int) $a_context;
447 return self::$closing_context;
457 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
Create styles array
The data for the language used.
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.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
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.