ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 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:$

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 200 of file class.ilSession.php.

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

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

201  {
202  global $ilDB;
203 
204  if(!$a_closing_context)
205  {
206  $a_closing_context = self::$closing_context;
207  }
208 
209  ilSessionStatistics::closeRawEntry($a_session_id, $a_closing_context, $a_expired_at);
210 
211 
212  if(!is_array($a_session_id))
213  {
214  $q = "DELETE FROM usr_session WHERE session_id = ".
215  $ilDB->quote($a_session_id, "text");
216  }
217  else
218  {
219  // array: id => timestamp - so we get rid of timestamps
220  if($a_expired_at)
221  {
222  $a_session_id = array_keys($a_session_id);
223  }
224  $q = "DELETE FROM usr_session WHERE ".
225  $ilDB->in("session_id", $a_session_id, "", "text");
226  }
227 
228  ilSessionIStorage::destroySession($a_session_id);
229 
230  $ilDB->manipulate($q);
231 
232  return true;
233  }
static destroySession($a_session_id)
Destroy session(s).
global $ilDB
static closeRawEntry($a_session_id, $a_context=null, $a_expired_at=null)
Close raw data entry.
+ 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 240 of file class.ilSession.php.

References $ilDB.

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

241  {
242  global $ilDB;
243 
244  $q = "DELETE FROM usr_session WHERE user_id = ".
245  $ilDB->quote($a_user_id, "integer");
246  $ilDB->manipulate($q);
247 
248  return true;
249  }
global $ilDB
+ Here is the caller graph for this function:

◆ _destroyExpiredSessions()

static ilSession::_destroyExpiredSessions ( )
static

Destroy expired sessions.

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

References $ilDB, $res, $row, array, and time.

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

255  {
256  global $ilDB;
257 
258  $q = "SELECT session_id,expires FROM usr_session WHERE expires < ".
259  $ilDB->quote(time(), "integer");
260  $res = $ilDB->query($q);
261  $ids = array();
262  while($row = $ilDB->fetchAssoc($res))
263  {
264  $ids[$row["session_id"]] = $row["expires"];
265  }
266  if(sizeof($ids))
267  {
268  self::_destroy($ids, self::SESSION_CLOSE_EXPIRE, true);
269  }
270 
271  return true;
272  }
Create styles array
The data for the language used.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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 280 of file class.ilSession.php.

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

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

281  {
282  global $ilDB;
283 
284  // Create new session id
285  $new_session = $a_session_id;
286  do
287  {
288  $new_session = md5($new_session);
289  $q ="SELECT * FROM usr_session WHERE ".
290  "session_id = ".$ilDB->quote($new_session, "text");
291  $res = $ilDB->query($q);
292  } while($ilDB->fetchAssoc($res));
293 
294  $query = "SELECT * FROM usr_session ".
295  "WHERE session_id = ".$ilDB->quote($a_session_id, "text");
296  $res = $ilDB->query($query);
297 
298  while ($row = $ilDB->fetchObject($res))
299  {
300  ilSession::_writeData($new_session,$row->data);
301  return $new_session;
302  }
303  return false;
304  }
static _writeData($a_session_id, $a_data)
Write session data.
global $ilDB
+ 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 180 of file class.ilSession.php.

References $ilDB.

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

181  {
182  if (! $a_session_id) {
183  return false;
184  }
185  global $ilDB;
186 
187  $q = "SELECT 1 FROM usr_session WHERE session_id = " . $ilDB->quote($a_session_id, "text");
188  $set = $ilDB->query($q);
189 
190  return $ilDB->numRows($set) > 0;
191  }
global $ilDB
+ 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.

References $ilDB.

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

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  }
global $ilDB
+ 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 378 of file class.ilSession.php.

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

379  {
380  global $ilDB;
381 
382  $query = "SELECT DISTINCT user_id FROM usr_session"
383  . " WHERE remote_addr = " . $ilDB->quote($a_ip, "text")
384  . " AND user_id > 0";
385  $result = $ilDB->query($query);
386 
387  $users = array();
388  while ($row = $ilDB->fetchObject($result))
389  {
390  $users[] = $row->user_id;
391  }
392  return $users;
393  }
$result
Create styles array
The data for the language used.
global $ilDB

◆ _writeData()

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

Write session data.

Parameters
stringsession id
stringsession data

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

References $_SERVER, $_SESSION, $ilDB, ilSessionControl\$session_types_controlled, _exists(), ilSessionStatistics\aggretateRaw(), array, ilSessionStatistics\createRawEntry(), and time.

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

114  {
115  global $ilDB, $ilClientIniFile;
116 
117  if (self::isWebAccessWithoutSessionEnabled())
118  {
119  // Prevent session data written for web access checker
120  // when no cookie was sent (e.g. for pdf files linking others).
121  // This would result in new session records for each request.
122  return true;
123  }
124 
125  $now = time();
126 
127  // prepare session data
128  $fields = array(
129  "user_id" => array("integer", (int) $_SESSION['_authsession_user_id']),
130  "expires" => array("integer", self::getExpireValue()),
131  "data" => array("clob", $a_data),
132  "ctime" => array("integer", $now),
133  "type" => array("integer", (int) $_SESSION["SessionType"])
134  );
135  if ($ilClientIniFile->readVariable("session","save_ip"))
136  {
137  $fields["remote_addr"] = array("text", $_SERVER["REMOTE_ADDR"]);
138  }
139 
140  if (ilSession::_exists($a_session_id))
141  {
142  $ilDB->update("usr_session", $fields,
143  array("session_id" => array("text", $a_session_id)));
144  }
145  else
146  {
147  $fields["session_id"] = array("text", $a_session_id);
148  $fields["createtime"] = array("integer", $now);
149 
150  $ilDB->insert("usr_session", $fields);
151 
152  // check type against session control
153  $type = $fields["type"][1];
155  {
156  ilSessionStatistics::createRawEntry($fields["session_id"][1],
157  $type, $fields["createtime"][1], $fields["user_id"][1]);
158  }
159  }
160 
161  // finally delete deprecated sessions
162  if(rand(0, 50) == 2)
163  {
164  // get time _before_ destroying expired sessions
165  self::_destroyExpiredSessions();
167  }
168 
169  return true;
170  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$_SESSION["AccountId"]
static _exists($a_session_id)
Check whether session exists.
static createRawEntry($a_session_id, $a_session_type, $a_timestamp, $a_user_id)
Create raw data entry.
Create styles array
The data for the language used.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static aggretateRaw($a_now)
Aggregate raw session data (older than given time)
+ 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 461 of file class.ilSession.php.

References $enable_web_access_without_session.

Referenced by ilNotificationGUI\getOSDNotificationsObject(), ilOnScreenChatGUI\getUserProfileImages(), ilNotificationGUI\removeOSDNotificationsObject(), and ilOnScreenChatGUI\verifyLogin().

462  {
463  self::$enable_web_access_without_session = (bool)$enable_web_access_without_session;
464  }
static $enable_web_access_without_session
+ Here is the caller graph for this function:

◆ get()

static ilSession::get (   $a_var)
static

Get a value.

Parameters

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

References $_SESSION.

Referenced by ilAccountRegistrationGUI\__distributeMails(), ilMailFolderGUI\addSubfolderCommands(), ilUserRequestTargetAdjustment\adjust(), ilPersonalSettingsGUI\allowPasswordChange(), ilMailFolderGUI\cancelDeleteMails(), ilObjectGUI\confirmedDeleteObject(), ilStartUpGUI\doMigration(), ilStartUpGUI\doMigrationNewAccount(), ilMailGUI\executeCommand(), ilTemplate\fillMessage(), ilStartUpGUI\getAcceptance(), ilHelpMappingTableGUI\getChapters(), ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilAwarenessGUI\getMainMenuHTML(), ilMailFormCall\getRecipients(), ilMailFormCall\getRefererRedirectUrl(), ilMailFormCall\getSignature(), ilMailMemberSearchGUI\getStoredReferer(), ilLanguage\getUserLanguage(), ilObjUser\hasToAcceptTermsOfServiceInSession(), ilAuthSession\init(), ilInitialisation\initCore(), ilHelpGUI\initHelp(), ilObjForumGUI\initSessionStorage(), ilMailFormCall\isRefererStored(), ilTestPlayerAbstractGUI\isTestSignRedirectRequired(), ilAuthFrontend\migrateAccount(), ilStartUpGUI\migrateAccount2(), 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(), ilMailGUI\showHeader(), ilHelpGUI\showHelp(), ilHelpGUI\showPage(), ilObjContentObjectGUI\showTooltipList(), ilMailFormCall\storeReferer(), ilMailMemberSearchGUI\storeReferer(), and ilUserRequestTargetAdjustment\storeRequest().

413  {
414  return $_SESSION[$a_var];
415  }
$_SESSION["AccountId"]
+ Here is the caller graph for this function:

◆ getClosingContext()

static ilSession::getClosingContext ( )
static

get closing context (for statistics)

Returns
int

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

444  {
445  return self::$closing_context;
446  }

◆ 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 public

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

References $ilSetting, ilSessionControl\DEFAULT_MAX_IDLE, and time.

317  {
318  global $ilSetting;
319 
320  if( $fixedMode || $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED )
321  {
322  // fixed session
323  return time() + self::getIdleValue($fixedMode);
324  }
325  else if( $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT )
326  {
327  // load dependent session settings
328  return time() + (int) ($ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE) * 60);
329  }
330  }
global $ilSetting
Definition: privfeed.php:17
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

◆ 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 public

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

References $ilSetting, and ilSessionControl\DEFAULT_MAX_IDLE.

Referenced by ilAuthUtils\_initAuth(), ilObjSCORMInitData\getIliasScormVars(), ilSCORM13Player\getPlayer(), and ilSessionReminder\initWithUserContext().

343  {
344  global $ilSetting, $ilClientIniFile;
345 
346  if( $fixedMode || $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED )
347  {
348  // fixed session
349  return $ilClientIniFile->readVariable('session','expire');
350  }
351  else if( $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT )
352  {
353  // load dependent session settings
354  return (int) ($ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE) * 60);
355  }
356  }
global $ilSetting
Definition: privfeed.php:17
+ 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 public

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

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

368  {
369  return self::getIdleValue(true);
370  }
+ Here is the caller graph for this function:

◆ isWebAccessWithoutSessionEnabled()

static ilSession::isWebAccessWithoutSessionEnabled ( )
static
Returns
boolean

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

454  {
455  return (bool)self::$enable_web_access_without_session;
456  }

◆ lookupExpireTime()

static ilSession::lookupExpireTime (   $a_session_id)
static

Lookup expire time for a specific session ilDB $ilDB.

Parameters
string$a_session_id
Returns
int expired unix timestamp

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

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

Referenced by ilAuthSession\validateExpiration().

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  {
101  return (int) $row->expires;
102  }
103  return 0;
104  }
global $ilDB
+ Here is the caller graph for this function:

◆ set()

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

Set a value.

Parameters

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

References $_SESSION.

Referenced by ilAccountRegistrationGUI\__distributeMails(), ilObjContentObjectGUI\addTooltip(), ilUserRequestTargetAdjustment\adjust(), ilObjectGUI\deleteObject(), ilTestSignatureGUI\executeCommand(), ilMailGUI\executeCommand(), ilObjContentObjectGUI\filterHelpChapters(), ilObjContentObjectGUI\filterTooltips(), ilStartUpGUI\getAcceptance(), ilAwarenessGUI\getAwarenessList(), ilAwarenessGUI\getMainMenuHTML(), ilMailFormCall\getRefererRedirectUrl(), ilMailFormCall\getSignature(), ilTestSignatureGUI\getTestOutputGUI(), ilLanguage\getUserLanguage(), ilAuthFrontend\handleAccountMigration(), ilAuthFrontend\handleAuthenticationSuccess(), ilObjUser\hasToAcceptTermsOfServiceInSession(), ilObjectGUI\hitsperpageObject(), ilInitialisation\initHTML(), ilObjForumGUI\initSessionStorage(), ilAwarenessAct\notifyOnNewOnlineContacts(), ilUserClipboard\save(), ilPersonalSettingsGUI\savePassword(), ilPersonalProfileGUI\savePersonalData(), ilHelpGUI\search(), ilAuthSession\setAuthenticated(), ilMailFormCall\setContextId(), ilMailFormCall\setContextParameters(), ilAuthSession\setExpired(), ilTemplate\setMessage(), ilMailFormCall\setRecipients(), ilTemplate\show(), ilHelpGUI\showHelp(), ilHelpGUI\showPage(), ilMailFormCall\storeReferer(), ilMailMemberSearchGUI\storeReferer(), ilUserRequestTargetAdjustment\storeRequest(), and ilMailMemberSearchGUI\unsetStoredReferer().

402  {
403  $_SESSION[$a_var] = $a_val;
404  }
$_SESSION["AccountId"]
+ Here is the caller graph for this function:

◆ setClosingContext()

static ilSession::setClosingContext (   $a_context)
static

Field Documentation

◆ $closing_context

ilSession::$closing_context = null
staticprivate

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

◆ $enable_web_access_without_session

ilSession::$enable_web_access_without_session = false
staticprotected

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

Referenced by enableWebAccessWithoutSession().

◆ 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: