ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSession Class Reference
+ Collaboration diagram for ilSession:

Static Public Member Functions

static _getData ($a_session_id)
 Get session data from table. More...
 
static lookupExpireTime ($a_session_id)
 Lookup expire time for a specific session @global ilDB $ilDB. More...
 
static _writeData ($a_session_id, $a_data)
 Write session data. More...
 
static _exists ($a_session_id)
 Check whether session exists. More...
 
static _destroy ($a_session_id, $a_closing_context=null, $a_expired_at=null)
 Destroy session. More...
 
static _destroyByUserId ($a_user_id)
 Destroy session. More...
 
static _destroyExpiredSessions ()
 Destroy expired sessions. More...
 
static _duplicate ($a_session_id)
 Duplicate session. More...
 
static getExpireValue ($fixedMode=false)
 Returns the expiration timestamp in seconds. More...
 
static getIdleValue ($fixedMode=false)
 Returns the idle time in seconds. More...
 
static getSessionExpireValue ()
 Returns the session expiration value. More...
 
static _getUsersWithIp ($a_ip)
 Get the active users with a specific remote ip address. More...
 
static set ($a_var, $a_val)
 Set a value. More...
 
static get ($a_var)
 Get a value. More...
 
static clear ($a_var)
 Unset a value. More...
 
static setClosingContext ($a_context)
 set closing context (for statistics) More...
 
static getClosingContext ()
 get closing context (for statistics) More...
 
static isWebAccessWithoutSessionEnabled ()
 
static enableWebAccessWithoutSession ($enable_web_access_without_session)
 

Data Fields

const SESSION_HANDLING_FIXED = 0
 
const SESSION_HANDLING_LOAD_DEPENDENT = 1
 
const SESSION_CLOSE_USER = 1
 
const SESSION_CLOSE_EXPIRE = 2
 
const SESSION_CLOSE_FIRST = 3
 
const SESSION_CLOSE_IDLE = 4
 
const SESSION_CLOSE_LIMIT = 5
 
const SESSION_CLOSE_LOGIN = 6
 
const SESSION_CLOSE_PUBLIC = 7
 
const SESSION_CLOSE_TIME = 8
 
const SESSION_CLOSE_IP = 9
 
const SESSION_CLOSE_SIMUL = 10
 
const SESSION_CLOSE_INACTIVE = 11
 
const SESSION_CLOSE_CAPTCHA = 12
 

Static Protected Attributes

static $enable_web_access_without_session = false
 

Static Private Attributes

static $closing_context = null
 

Detailed Description

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id:$

@externalTableAccess ilObjUser on usr_session

Definition at line 15 of file class.ilSession.php.

Member Function Documentation

◆ _destroy()

static ilSession::_destroy (   $a_session_id,
  $a_closing_context = null,
  $a_expired_at = null 
)
static

Destroy session.

Parameters
string|arraysession id|s
intclosing context
int|boolexpired at timestamp

Definition at line 218 of file class.ilSession.php.

219 {
220 global $ilDB;
221
222 if (!$a_closing_context) {
223 $a_closing_context = self::$closing_context;
224 }
225
226 ilSessionStatistics::closeRawEntry($a_session_id, $a_closing_context, $a_expired_at);
227
228
229 if (!is_array($a_session_id)) {
230 $q = "DELETE FROM usr_session WHERE session_id = " .
231 $ilDB->quote($a_session_id, "text");
232 } else {
233 // array: id => timestamp - so we get rid of timestamps
234 if ($a_expired_at) {
235 $a_session_id = array_keys($a_session_id);
236 }
237 $q = "DELETE FROM usr_session WHERE " .
238 $ilDB->in("session_id", $a_session_id, "", "text");
239 }
240
242
243 $ilDB->manipulate($q);
244
245 return true;
246 }
static destroySession($a_session_id)
Destroy session(s).
static closeRawEntry($a_session_id, $a_context=null, $a_expired_at=null)
Close raw data entry.
static $closing_context
global $ilDB

References $closing_context, $ilDB, ilSessionStatistics\closeRawEntry(), and ilSessionIStorage\destroySession().

Referenced by _destroyExpiredSessions(), ilSessionDBHandler\destroy(), ilSessionControl\kickFirstRequestAbidencer(), ilSessionControl\kickOneMinIdleSession(), and ilSessionTest\testBasicSessionBehaviour().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _destroyByUserId()

static ilSession::_destroyByUserId (   $a_user_id)
static

Destroy session.

Parameters
stringsession id

Definition at line 253 of file class.ilSession.php.

254 {
255 global $ilDB;
256
257 $q = "DELETE FROM usr_session WHERE user_id = " .
258 $ilDB->quote($a_user_id, "integer");
259 $ilDB->manipulate($q);
260
261 return true;
262 }

References $ilDB.

Referenced by ilObjUser\delete(), and ilSessionTest\testBasicSessionBehaviour().

+ Here is the caller graph for this function:

◆ _destroyExpiredSessions()

static ilSession::_destroyExpiredSessions ( )
static

Destroy expired sessions.

Definition at line 267 of file class.ilSession.php.

268 {
269 global $ilDB;
270
271 $q = "SELECT session_id,expires FROM usr_session WHERE expires < " .
272 $ilDB->quote(time(), "integer");
273 $res = $ilDB->query($q);
274 $ids = array();
275 while ($row = $ilDB->fetchAssoc($res)) {
276 $ids[$row["session_id"]] = $row["expires"];
277 }
278 if (sizeof($ids)) {
279 self::_destroy($ids, self::SESSION_CLOSE_EXPIRE, true);
280 }
281
282 return true;
283 }
static _destroy($a_session_id, $a_closing_context=null, $a_expired_at=null)
Destroy session.
foreach($_POST as $key=> $value) $res

References $ilDB, $res, $row, and _destroy().

Referenced by _writeData(), ilSessionStatisticsGUI\adminSync(), ilSessionDBHandler\gc(), and ilSessionTest\testBasicSessionBehaviour().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _duplicate()

static ilSession::_duplicate (   $a_session_id)
static

Duplicate session.

Parameters
stringsession id
Returns
string new session id

Definition at line 291 of file class.ilSession.php.

292 {
293 global $ilDB;
294
295 // Create new session id
296 $new_session = $a_session_id;
297 do {
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));
303
304 $query = "SELECT * FROM usr_session " .
305 "WHERE session_id = " . $ilDB->quote($a_session_id, "text");
306 $res = $ilDB->query($query);
307
308 while ($row = $ilDB->fetchObject($res)) {
309 ilSession::_writeData($new_session, $row->data);
310 return $new_session;
311 }
312 return false;
313 }
static _writeData($a_session_id, $a_data)
Write session data.
$query

References $ilDB, $query, $res, $row, and _writeData().

Referenced by ilContainer\cloneAllObject(), ilDclContentExporter\exportAsync(), ilECSTaskScheduler\initNextExecution(), and ilSessionTest\testBasicSessionBehaviour().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _exists()

static ilSession::_exists (   $a_session_id)
static

Check whether session exists.

Parameters
stringsession id
Returns
boolean true, if session id exists

Definition at line 198 of file class.ilSession.php.

199 {
200 if (!$a_session_id) {
201 return false;
202 }
203 global $ilDB;
204
205 $q = "SELECT 1 FROM usr_session WHERE session_id = " . $ilDB->quote($a_session_id, "text");
206 $set = $ilDB->query($q);
207
208 return $ilDB->numRows($set) > 0;
209 }

References $ilDB.

Referenced by _writeData(), ilInitialisation\setSessionHandler(), and ilSessionTest\testBasicSessionBehaviour().

+ Here is the caller graph for this function:

◆ _getData()

static ilSession::_getData (   $a_session_id)
static

Get session data from table.

According to https://bugs.php.net/bug.php?id=70520 read data must return a string. Otherwise session_regenerate_id might fail with php 7.

Parameters
stringsession id
Returns
string session data

Definition at line 69 of file class.ilSession.php.

70 {
71 if (!$a_session_id) {
72 // fix for php #70520
73 return '';
74 }
75 global $ilDB;
76
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);
81
82 // fix for php #70520
83 return (string) $rec["data"];
84 }

References $ilDB.

Referenced by ilSessionDBHandler\read(), and ilSessionTest\testBasicSessionBehaviour().

+ Here is the caller graph for this function:

◆ _getUsersWithIp()

static ilSession::_getUsersWithIp (   $a_ip)
static

Get the active users with a specific remote ip address.

Parameters
stringip address
Returns
array list of active user id

Definition at line 381 of file class.ilSession.php.

382 {
383 global $ilDB;
384
385 $query = "SELECT DISTINCT user_id FROM usr_session"
386 . " WHERE remote_addr = " . $ilDB->quote($a_ip, "text")
387 . " AND user_id > 0";
388 $result = $ilDB->query($query);
389
390 $users = array();
391 while ($row = $ilDB->fetchObject($result)) {
392 $users[] = $row->user_id;
393 }
394 return $users;
395 }
$result
$users
Definition: authpage.php:44

References $ilDB, $query, $result, $row, and $users.

◆ _writeData()

static ilSession::_writeData (   $a_session_id,
  $a_data 
)
static

Write session data.

Parameters
stringsession id
stringsession data

Definition at line 112 of file class.ilSession.php.

113 {
114 global $ilDB, $ilClientIniFile;
115
116 if (self::isWebAccessWithoutSessionEnabled()) {
117 // Prevent session data written for web access checker
118 // when no cookie was sent (e.g. for pdf files linking others).
119 // This would result in new session records for each request.
120 return true;
121 }
122
123 if (!$a_session_id) {
124 return true;
125 }
126
127 $now = time();
128
129 // prepare session data
130 $fields = array(
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"])
136 );
137 if ($ilClientIniFile->readVariable("session", "save_ip")) {
138 $fields["remote_addr"] = array("text", $_SERVER["REMOTE_ADDR"]);
139 }
140
141 if (ilSession::_exists($a_session_id)) {
142 // note that we do this only when inserting the new record
143 // updating may get us other contexts for the same session, especially ilContextWAC, which we do not want
144 if (class_exists("ilContext")) {
146 $fields["context"] = array("text", ilContext::getType());
147 }
148 }
149
150 $ilDB->update(
151 "usr_session",
152 $fields,
153 array("session_id" => array("text", $a_session_id))
154 );
155 } else {
156 $fields["session_id"] = array("text", $a_session_id);
157 $fields["createtime"] = array("integer", $now);
158
159 // note that we do this only when inserting the new record
160 // updating may get us other contexts for the same session, especially ilContextWAC, which we do not want
161 if (class_exists("ilContext")) {
162 $fields["context"] = array("text", ilContext::getType());
163 }
164
165 $ilDB->insert("usr_session", $fields);
166
167 // check type against session control
168 $type = $fields["type"][1];
171 $fields["session_id"][1],
172 $type,
173 $fields["createtime"][1],
174 $fields["user_id"][1]
175 );
176 }
177 }
178
179 // finally delete deprecated sessions
180 $random = new \ilRandom();
181 if ($random->int(0, 50) == 2) {
182 // get time _before_ destroying expired sessions
185 }
186
187 return true;
188 }
$_SESSION["AccountId"]
static isSessionMainContext()
Context that are not only temporary in a session (e.g.
static getType()
Get context type.
static createRawEntry($a_session_id, $a_session_type, $a_timestamp, $a_user_id)
Create raw data entry.
static aggretateRaw($a_now)
Aggregate raw session data (older than given time)
static _exists($a_session_id)
Check whether session exists.
static _destroyExpiredSessions()
Destroy expired sessions.
$type
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

References $_SERVER, $_SESSION, $ilDB, ilSessionControl\$session_types_controlled, $type, _destroyExpiredSessions(), _exists(), ilSessionStatistics\aggretateRaw(), ilSessionStatistics\createRawEntry(), ilContext\getType(), and ilContext\isSessionMainContext().

Referenced by _duplicate(), ilSessionTest\testBasicSessionBehaviour(), and ilSessionDBHandler\write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

◆ enableWebAccessWithoutSession()

static ilSession::enableWebAccessWithoutSession (   $enable_web_access_without_session)
static
Parameters
boolean$enable_web_access_without_session

Definition at line 463 of file class.ilSession.php.

464 {
465 self::$enable_web_access_without_session = (bool) $enable_web_access_without_session;
466 }
static $enable_web_access_without_session

References $enable_web_access_without_session.

Referenced by ilWebDAVAuthentication\authenticate(), ilNotificationGUI\getOSDNotificationsObject(), ilOnScreenChatGUI\getUserProfileData(), ilNotificationGUI\removeOSDNotificationsObject(), and ilOnScreenChatGUI\verifyLogin().

+ Here is the caller graph for this function:

◆ get()

static ilSession::get (   $a_var)
static

Get a value.

Parameters

return

Definition at line 414 of file class.ilSession.php.

415 {
416 return $_SESSION[$a_var];
417 }

References $_SESSION.

Referenced by ilCalendarAgendaListGUI\__construct(), ilMailFolderGUI\addSubfolderCommands(), ilUserRequestTargetAdjustment\adjust(), ilPersonalSettingsGUI\allowPasswordChange(), ilObjectGUI\confirmedDeleteObject(), ilAuthProviderSaml\createNewAccount(), ilStartUpGUI\doMigration(), ilStartUpGUI\doMigrationNewAccount(), ilMailGUI\executeCommand(), ilTemplate\fillMessage(), ilCalendarPresentationGUI\forwardToClass(), ilCalendarViewGUI\getBucketTitle(), ilHelpMappingTableGUI\getChapters(), ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilAwarenessGUI\getMainMenuHTML(), ilCalendarAgendaListGUI\getPeriod(), ilMailFormCall\getRecipients(), ilMailFormCall\getRefererRedirectUrl(), ilMailFormCall\getSignature(), ilMailMemberSearchGUI\getStoredReferer(), ilObjUser\hasToAcceptTermsOfServiceInSession(), ilAuthSession\init(), ilInitialisation\initCore(), ilHelpGUI\initHelp(), ilObjForumGUI\initSessionStorage(), ilMailFormCall\isRefererStored(), ilTestPlayerAbstractGUI\isTestSignRedirectRequired(), ilAuthFrontend\migrateAccount(), ilAwarenessAct\notifyOnNewOnlineContacts(), ilMailFolderGUI\performAddSubFolder(), ilMailFolderGUI\performRenameSubFolder(), ilUserClipboard\read(), ilPersonalSettingsGUI\savePassword(), ilPersonalProfileGUI\savePersonalData(), ilHelpGUI\search(), ilMailFormCall\setContextId(), ilMailFormCall\setContextParameters(), ilMailFormCall\setRecipients(), ilUserPasswordResetRequestTargetAdjustmentCase\shouldAdjustRequest(), ilTemplate\show(), ilObjContentObjectGUI\showExportIDsOverview(), ilMailFolderGUI\showFolder(), ilMailGUI\showHeader(), ilHelpGUI\showHelp(), ilStartUpGUI\showLogout(), ilHelpGUI\showPage(), ilObjContentObjectGUI\showTooltipList(), ilMailFormCall\storeReferer(), ilMailMemberSearchGUI\storeReferer(), and ilUserRequestTargetAdjustment\storeRequest().

+ Here is the caller graph for this function:

◆ getClosingContext()

static ilSession::getClosingContext ( )
static

get closing context (for statistics)

Returns
int

Definition at line 445 of file class.ilSession.php.

446 {
448 }

References $closing_context.

◆ getExpireValue()

static ilSession::getExpireValue (   $fixedMode = false)
static

Returns the expiration timestamp in seconds.

Parameters
booleanIf passed, the value for fixed session is returned
Returns
integer The expiration timestamp in seconds @access public

Definition at line 325 of file class.ilSession.php.

326 {
327 global $ilSetting;
328
329 if ($fixedMode || $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED) {
330 // fixed session
331 return time() + self::getIdleValue($fixedMode);
332 } elseif ($ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT) {
333 // load dependent session settings
334 return time() + (int) ($ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE) * 60);
335 }
336 }
static getIdleValue($fixedMode=false)
Returns the idle time in seconds.
global $ilSetting
Definition: privfeed.php:17

References $ilSetting, ilSessionControl\DEFAULT_MAX_IDLE, and getIdleValue().

+ Here is the call graph for this function:

◆ getIdleValue()

static ilSession::getIdleValue (   $fixedMode = false)
static

Returns the idle time in seconds.

Parameters
booleanIf passed, the value for fixed session is returned
Returns
integer The idle time in seconds @access public

Definition at line 348 of file class.ilSession.php.

349 {
350 global $ilSetting, $ilClientIniFile;
351
352 if ($fixedMode || $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED) {
353 // fixed session
354 return $ilClientIniFile->readVariable('session', 'expire');
355 } elseif ($ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT) {
356 // load dependent session settings
357 return (int) ($ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE) * 60);
358 }
359 }

References $ilSetting, and ilSessionControl\DEFAULT_MAX_IDLE.

Referenced by getExpireValue(), ilObjSCORMInitData\getIliasScormVars(), ilSCORM13Player\getPlayer(), getSessionExpireValue(), and ilSessionReminder\initWithUserContext().

+ Here is the caller graph for this function:

◆ getSessionExpireValue()

static ilSession::getSessionExpireValue ( )
static

Returns the session expiration value.

Returns
integer The expiration value in seconds @access public

Definition at line 370 of file class.ilSession.php.

371 {
372 return self::getIdleValue(true);
373 }

References getIdleValue().

Referenced by ilObjUserFolderGUI\initFormGeneralSettings(), and ilPersonalSettingsGUI\initGeneralSettingsForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isWebAccessWithoutSessionEnabled()

static ilSession::isWebAccessWithoutSessionEnabled ( )
static
Returns
boolean

Definition at line 455 of file class.ilSession.php.

456 {
458 }

References $enable_web_access_without_session.

◆ lookupExpireTime()

static ilSession::lookupExpireTime (   $a_session_id)
static

Lookup expire time for a specific session @global ilDB $ilDB.

Parameters
string$a_session_id
Returns
int expired unix timestamp

Definition at line 92 of file class.ilSession.php.

93 {
94 global $ilDB;
95
96 $query = 'SELECT expires FROM usr_session WHERE session_id = ' .
97 $ilDB->quote($a_session_id, 'text');
98 $res = $ilDB->query($query);
99 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
100 return (int) $row->expires;
101 }
102 return 0;
103 }

References $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilAuthSession\validateExpiration().

+ Here is the caller graph for this function:

◆ set()

static ilSession::set (   $a_var,
  $a_val 
)
static

◆ setClosingContext()

static ilSession::setClosingContext (   $a_context)
static

set closing context (for statistics)

Parameters
int$a_context

Definition at line 435 of file class.ilSession.php.

436 {
437 self::$closing_context = (int) $a_context;
438 }

Referenced by ilSessionControl\checkCurrentSessionIsAllowed(), ilPersonalSettingsGUI\deleteOwnAccountLogout(), ilInitialisation\goToLogin(), ilInitialisation\goToPublicSection(), ilSoapUserAdministration\loginStudipUser(), ilSoapUserAdministration\logout(), ilCronStartUp\logout(), ilLTIViewGUI\logout(), ilStartUpGUI\showLogin(), and ilStartUpGUI\showLogout().

+ Here is the caller graph for this function:

Field Documentation

◆ $closing_context

ilSession::$closing_context = null
staticprivate

Definition at line 53 of file class.ilSession.php.

Referenced by _destroy(), and getClosingContext().

◆ $enable_web_access_without_session

ilSession::$enable_web_access_without_session = false
staticprotected

◆ SESSION_CLOSE_CAPTCHA

const ilSession::SESSION_CLOSE_CAPTCHA = 12

Definition at line 51 of file class.ilSession.php.

Referenced by ilStartUpGUI\showLogin().

◆ SESSION_CLOSE_EXPIRE

const ilSession::SESSION_CLOSE_EXPIRE = 2

◆ SESSION_CLOSE_FIRST

const ilSession::SESSION_CLOSE_FIRST = 3

◆ SESSION_CLOSE_IDLE

const ilSession::SESSION_CLOSE_IDLE = 4

◆ SESSION_CLOSE_INACTIVE

const ilSession::SESSION_CLOSE_INACTIVE = 11

Definition at line 50 of file class.ilSession.php.

Referenced by ilStartUpGUI\showLogin().

◆ SESSION_CLOSE_IP

const ilSession::SESSION_CLOSE_IP = 9

Definition at line 48 of file class.ilSession.php.

Referenced by ilStartUpGUI\showLogin().

◆ SESSION_CLOSE_LIMIT

const ilSession::SESSION_CLOSE_LIMIT = 5

◆ SESSION_CLOSE_LOGIN

const ilSession::SESSION_CLOSE_LOGIN = 6

◆ SESSION_CLOSE_PUBLIC

const ilSession::SESSION_CLOSE_PUBLIC = 7

Definition at line 46 of file class.ilSession.php.

Referenced by ilInitialisation\goToPublicSection().

◆ SESSION_CLOSE_SIMUL

const ilSession::SESSION_CLOSE_SIMUL = 10

Definition at line 49 of file class.ilSession.php.

Referenced by ilStartUpGUI\showLogin().

◆ SESSION_CLOSE_TIME

const ilSession::SESSION_CLOSE_TIME = 8

Definition at line 47 of file class.ilSession.php.

Referenced by ilStartUpGUI\showLogin().

◆ SESSION_CLOSE_USER

◆ SESSION_HANDLING_FIXED

◆ SESSION_HANDLING_LOAD_DEPENDENT

const ilSession::SESSION_HANDLING_LOAD_DEPENDENT = 1

The documentation for this class was generated from the following file: