ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilSession Class Reference
+ Collaboration diagram for ilSession:

Static Public Member Functions

static _getData ($a_session_id)
 Get session data from table. 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 174 of file class.ilSession.php.

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

Referenced by ilSessionDBHandler\destroy(), ilInitialisation\initUser(), ilSessionControl\kickFirstRequestAbidencer(), ilSessionControl\kickOneMinIdleSession(), ilStartUpGUI\migrateAccount(), and ilSessionTest\testBasicSessionBehaviour().

175  {
176  global $ilDB;
177 
178  if(!$a_closing_context)
179  {
180  $a_closing_context = self::$closing_context;
181  }
182 
183  ilSessionStatistics::closeRawEntry($a_session_id, $a_closing_context, $a_expired_at);
184 
185 
186  if(!is_array($a_session_id))
187  {
188  $q = "DELETE FROM usr_session WHERE session_id = ".
189  $ilDB->quote($a_session_id, "text");
190  }
191  else
192  {
193  // array: id => timestamp - so we get rid of timestamps
194  if($a_expired_at)
195  {
196  $a_session_id = array_keys($a_session_id);
197  }
198  $q = "DELETE FROM usr_session WHERE ".
199  $ilDB->in("session_id", $a_session_id, "", "text");
200  }
201 
202  ilSessionIStorage::destroySession($a_session_id);
203 
204  $ilDB->manipulate($q);
205 
206  return true;
207  }
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 214 of file class.ilSession.php.

References $ilDB.

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

215  {
216  global $ilDB;
217 
218  $q = "DELETE FROM usr_session WHERE user_id = ".
219  $ilDB->quote($a_user_id, "integer");
220  $ilDB->manipulate($q);
221 
222  return true;
223  }
global $ilDB
+ Here is the caller graph for this function:

◆ _destroyExpiredSessions()

static ilSession::_destroyExpiredSessions ( )
static

Destroy expired sessions.

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

References $ilDB, $res, and $row.

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

229  {
230  global $ilDB;
231 
232  $q = "SELECT session_id,expires FROM usr_session WHERE expires < ".
233  $ilDB->quote(time(), "integer");
234  $res = $ilDB->query($q);
235  $ids = array();
236  while($row = $ilDB->fetchAssoc($res))
237  {
238  $ids[$row["session_id"]] = $row["expires"];
239  }
240  if(sizeof($ids))
241  {
242  self::_destroy($ids, self::SESSION_CLOSE_EXPIRE, true);
243  }
244 
245  return true;
246  }
global $ilDB
+ 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 254 of file class.ilSession.php.

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

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

255  {
256  global $ilDB;
257 
258  // Create new session id
259  $new_session = $a_session_id;
260  do
261  {
262  $new_session = md5($new_session);
263  $q ="SELECT * FROM usr_session WHERE ".
264  "session_id = ".$ilDB->quote($new_session, "text");
265  $res = $ilDB->query($q);
266  } while($ilDB->fetchAssoc($res));
267 
268  $query = "SELECT * FROM usr_session ".
269  "WHERE session_id = ".$ilDB->quote($a_session_id, "text");
270  $res = $ilDB->query($query);
271 
272  while ($row = $ilDB->fetchObject($res))
273  {
274  ilSession::_writeData($new_session,$row->data);
275  return $new_session;
276  }
277  return false;
278  }
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 154 of file class.ilSession.php.

References $ilDB.

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

155  {
156  if (! $a_session_id) {
157  return false;
158  }
159  global $ilDB;
160 
161  $q = "SELECT 1 FROM usr_session WHERE session_id = " . $ilDB->quote($a_session_id, "text");
162  $set = $ilDB->query($q);
163 
164  return $ilDB->numRows($set) > 0;
165  }
global $ilDB
+ Here is the caller graph for this function:

◆ _getData()

static ilSession::_getData (   $a_session_id)
static

Get session data from table.

Parameters
stringsession id
Returns
string session data

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

References $ilDB.

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

67  {
68  if(!$a_session_id) {
69  return NULL;
70  }
71  global $ilDB;
72 
73  $q = "SELECT data FROM usr_session WHERE session_id = ".
74  $ilDB->quote($a_session_id, "text");
75  $set = $ilDB->query($q);
76  $rec = $ilDB->fetchAssoc($set);
77 
78  return $rec["data"];
79  }
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 352 of file class.ilSession.php.

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

Referenced by ilWebAccessChecker\determineUser().

353  {
354  global $ilDB;
355 
356  $query = "SELECT DISTINCT user_id FROM usr_session"
357  . " WHERE remote_addr = " . $ilDB->quote($a_ip, "text")
358  . " AND user_id > 0";
359  $result = $ilDB->query($query);
360 
361  $users = array();
362  while ($row = $ilDB->fetchObject($result))
363  {
364  $users[] = $row->user_id;
365  }
366  return $users;
367  }
$result
global $ilDB
+ Here is the caller graph for this function:

◆ _writeData()

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

Write session data.

Parameters
stringsession id
stringsession data

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

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

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

88  {
89  global $ilDB, $ilClientIniFile;
90 
91  if (self::isWebAccessWithoutSessionEnabled())
92  {
93  // Prevent session data written for web access checker
94  // when no cookie was sent (e.g. for pdf files linking others).
95  // This would result in new session records for each request.
96  return true;
97  }
98 
99  $now = time();
100 
101  // prepare session data
102  $fields = array(
103  "user_id" => array("integer", (int) $_SESSION["AccountId"]),
104  "expires" => array("integer", self::getExpireValue()),
105  "data" => array("clob", $a_data),
106  "ctime" => array("integer", $now),
107  "type" => array("integer", (int) $_SESSION["SessionType"])
108  );
109  if ($ilClientIniFile->readVariable("session","save_ip"))
110  {
111  $fields["remote_addr"] = array("text", $_SERVER["REMOTE_ADDR"]);
112  }
113 
114  if (ilSession::_exists($a_session_id))
115  {
116  $ilDB->update("usr_session", $fields,
117  array("session_id" => array("text", $a_session_id)));
118  }
119  else
120  {
121  $fields["session_id"] = array("text", $a_session_id);
122  $fields["createtime"] = array("integer", $now);
123 
124  $ilDB->insert("usr_session", $fields);
125 
126  // check type against session control
127  $type = $fields["type"][1];
129  {
130  ilSessionStatistics::createRawEntry($fields["session_id"][1],
131  $type, $fields["createtime"][1], $fields["user_id"][1]);
132  }
133  }
134 
135  // finally delete deprecated sessions
136  if(rand(0, 50) == 2)
137  {
138  // get time _before_ destroying expired sessions
139  self::_destroyExpiredSessions();
141  }
142 
143  return true;
144  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
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.
global $ilDB
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()

static ilSession::clear (   $a_var)
static

Unset a value.

Parameters

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

References $_SESSION.

Referenced by ilObjiLincUserGUI\cancel(), ilLMObjectGUI\cancelDelete(), ilObjiLincClassroomGUI\cancelDeleteClassroom(), ilSCORM2004ScoGUI\cancelDeleteExportFile(), ilObjSCORM2004LearningModuleGUI\cancelDeleteExportFile(), ilObjSurveyQuestionPoolGUI\cancelDeleteExportFileObject(), ilObjectGUI\cancelDeleteObject(), ilObjUserGUI\cancelObject(), ilObjectGUI\cancelObject(), ilObjectGUI\checkPermission(), ilObjectGUI\confirmedDeleteObject(), ilRepUtil\deleteObjects(), ilTemplate\fillMessage(), ilUtil\infoPanel(), ilHelpGUI\resetCurrentPage(), ilTemplate\show(), and ilPageObjectGUI\showPage().

398  {
399  unset($_SESSION[$a_var]);
400  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
+ Here is the caller graph for this function:

◆ enableWebAccessWithoutSession()

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

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

References $enable_web_access_without_session.

Referenced by ilNotificationGUI\getOSDNotificationsObject(), and ilNotificationGUI\removeOSDNotificationsObject().

434  {
435  self::$enable_web_access_without_session = (bool)$enable_web_access_without_session;
436  }
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 386 of file class.ilSession.php.

References $_SESSION.

Referenced by ilAccountRegistrationGUI\__distributeMails(), ilMailFolderGUI\addSubfolderCommands(), ilMailFolderGUI\cancelDeleteMails(), ilObjectGUI\confirmedDeleteObject(), ilMailGUI\executeCommand(), ilTemplate\fillMessage(), ilStartUpGUI\getAcceptance(), ilHelpMappingTableGUI\getChapters(), ilMailFormCall\getRecipients(), ilObjUser\hasToAcceptTermsOfServiceInSession(), ilUserRequestTargetAdjustment\initCases(), ilInitialisation\initCore(), ilHelpGUI\initHelp(), ilInitialisation\initLanguage(), ilObjForumGUI\initSessionStorage(), ilInitialisation\initStyle(), ilTestPlayerAbstractGUI\isTestSignRedirectRequired(), ilStartUpGUI\migrateAccount(), ilMailFolderGUI\performAddSubFolder(), ilMailFolderGUI\performRenameSubFolder(), ilPersonalSettingsGUI\savePassword(), ilPersonalProfileGUI\savePersonalData(), ilMailFormCall\setRecipients(), ilTemplate\show(), ilObjContentObjectGUI\showExportIDsOverview(), ilMailGUI\showHeader(), ilHelpGUI\showHelp(), and ilObjContentObjectGUI\showTooltipList().

387  {
388  return $_SESSION[$a_var];
389  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
+ Here is the caller graph for this function:

◆ getClosingContext()

static ilSession::getClosingContext ( )
static

get closing context (for statistics)

Returns
int

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

418  {
419  return self::$closing_context;
420  }

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

References $ilSetting, and ilSessionControl\DEFAULT_MAX_IDLE.

291  {
292  global $ilSetting;
293 
294  if( $fixedMode || $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED )
295  {
296  // fixed session
297  return time() + ini_get('session.gc_maxlifetime');
298  }
299  else if( $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT )
300  {
301  // load dependent session settings
302  return time() + (int) ($ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE) * 60);
303  }
304  }
global $ilSetting
Definition: privfeed.php:40

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

References $ilSetting, and ilSessionControl\DEFAULT_MAX_IDLE.

Referenced by ilAuthUtils\_initAuth(), ilTestPlayerAbstractGUI\finishTestCmd(), and ilSCORM13Player\getPlayer().

317  {
318  global $ilSetting, $ilClientIniFile;
319 
320  if( $fixedMode || $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED )
321  {
322  // fixed session
323  return $ilClientIniFile->readVariable('session','expire');
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 (int) ($ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE) * 60);
329  }
330  }
global $ilSetting
Definition: privfeed.php:40
+ 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 341 of file class.ilSession.php.

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

342  {
343  return self::getIdleValue(true);
344  }
+ Here is the caller graph for this function:

◆ isWebAccessWithoutSessionEnabled()

static ilSession::isWebAccessWithoutSessionEnabled ( )
static
Returns
boolean

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

426  {
427  return (bool)self::$enable_web_access_without_session;
428  }

◆ set()

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

Set a value.

Parameters

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

References $_SESSION.

Referenced by ilObjContentObjectGUI\addTooltip(), ilInitialisation\authenticate(), ilObjectGUI\deleteObject(), ilTestSignatureGUI\executeCommand(), ilMailGUI\executeCommand(), ilObjContentObjectGUI\filterHelpChapters(), ilObjContentObjectGUI\filterTooltips(), ilStartUpGUI\getAcceptance(), ilTestSignatureGUI\getTestOutputGUI(), ilObjUser\hasToAcceptTermsOfServiceInSession(), ilObjectGUI\hitsperpageObject(), ilUserRequestTargetAdjustment\initCases(), ilInitialisation\initLanguage(), ilObjForumGUI\initSessionStorage(), ilInitialisation\initStyle(), ilInitialisation\initUser(), ilStartUpGUI\migrateAccount(), ilPersonalSettingsGUI\savePassword(), ilPersonalProfileGUI\savePersonalData(), ilTemplate\setMessage(), ilMailFormCall\setRecipients(), ilTemplate\show(), ilHelpGUI\showHelp(), ilStartUpGUI\showLogin(), and ilHelpGUI\showPage().

376  {
377  $_SESSION[$a_var] = $a_val;
378  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
+ Here is the caller graph for this function:

◆ setClosingContext()

static ilSession::setClosingContext (   $a_context)
static

set closing context (for statistics)

Parameters
int$a_context

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

Referenced by ilSessionControl\checkCurrentSessionIsAllowed(), ilPersonalSettingsGUI\deleteOwnAccountLogout(), ilInitialisation\goToLogin(), ilInitialisation\goToPublicSection(), ilStartUpGUI\showLogin(), and ilStartUpGUI\showLogout().

408  {
409  self::$closing_context = (int)$a_context;
410  }
+ 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.

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

const ilSession::SESSION_CLOSE_USER = 1

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