ILIAS  release_4-4 Revision
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...
 

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

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

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

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

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

206  {
207  global $ilDB;
208 
209  $q = "DELETE FROM usr_session WHERE user_id = ".
210  $ilDB->quote($a_user_id, "integer");
211  $ilDB->manipulate($q);
212 
213  return true;
214  }
+ Here is the caller graph for this function:

◆ _destroyExpiredSessions()

static ilSession::_destroyExpiredSessions ( )
static

Destroy expired sessions.

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

References $res, and $row.

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

220  {
221  global $ilDB;
222 
223  $q = "SELECT session_id,expires FROM usr_session WHERE expires < ".
224  $ilDB->quote(time(), "integer");
225  $res = $ilDB->query($q);
226  $ids = array();
227  while($row = $ilDB->fetchAssoc($res))
228  {
229  $ids[$row["session_id"]] = $row["expires"];
230  }
231  if(sizeof($ids))
232  {
233  self::_destroy($ids, self::SESSION_CLOSE_EXPIRE, true);
234  }
235 
236  return true;
237  }
+ 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 245 of file class.ilSession.php.

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

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

246  {
247  global $ilDB;
248 
249  // Create new session id
250  $new_session = $a_session_id;
251  do
252  {
253  $new_session = md5($new_session);
254  $q ="SELECT * FROM usr_session WHERE ".
255  "session_id = ".$ilDB->quote($new_session, "text");
256  $res = $ilDB->query($q);
257  } while($ilDB->fetchAssoc($res));
258 
259  $query = "SELECT * FROM usr_session ".
260  "WHERE session_id = ".$ilDB->quote($a_session_id, "text");
261  $res = $ilDB->query($query);
262 
263  while ($row = $ilDB->fetchObject($res))
264  {
265  ilSession::_writeData($new_session,$row->data);
266  return $new_session;
267  }
268  return false;
269  }
static _writeData($a_session_id, $a_data)
Write session data.
+ 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 144 of file class.ilSession.php.

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

145  {
146  global $ilDB;
147 
148  $q = "SELECT session_id FROM usr_session WHERE session_id = ".
149  $ilDB->quote($a_session_id, "text");
150  $set = $ilDB->query($q);
151  if ($ilDB->fetchAssoc($set))
152  {
153  return true;
154  }
155  return false;
156  }
+ 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 61 of file class.ilSession.php.

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

62  {
63  global $ilDB;
64 
65  $q = "SELECT data FROM usr_session WHERE session_id = ".
66  $ilDB->quote($a_session_id, "text");
67  $set = $ilDB->query($q);
68  $rec = $ilDB->fetchAssoc($set);
69 
70  return $rec["data"];
71  }
+ 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 343 of file class.ilSession.php.

References $query, $result, and $row.

Referenced by ilWebAccessChecker\determineUser().

344  {
345  global $ilDB;
346 
347  $query = "SELECT DISTINCT user_id FROM usr_session"
348  . " WHERE remote_addr = " . $ilDB->quote($a_ip, "text")
349  . " AND user_id > 0";
350  $result = $ilDB->query($query);
351 
352  $users = array();
353  while ($row = $ilDB->fetchObject($result))
354  {
355  $users[] = $row->user_id;
356  }
357  return $users;
358  }
$result
+ 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 79 of file class.ilSession.php.

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

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

80  {
81  global $ilDB, $ilClientIniFile;
82 
83  if ($GLOBALS['WEB_ACCESS_WITHOUT_SESSION'])
84  {
85  // Prevent session data written for web access checker
86  // when no cookie was sent (e.g. for pdf files linking others).
87  // This would result in new session records for each request.
88  return false;
89  }
90 
91  $now = time();
92 
93  // prepare session data
94  $fields = array(
95  "user_id" => array("integer", (int) $_SESSION["AccountId"]),
96  "expires" => array("integer", self::getExpireValue()),
97  "data" => array("clob", $a_data),
98  "ctime" => array("integer", $now),
99  "type" => array("integer", (int) $_SESSION["SessionType"])
100  );
101  if ($ilClientIniFile->readVariable("session","save_ip"))
102  {
103  $fields["remote_addr"] = array("text", $_SERVER["REMOTE_ADDR"]);
104  }
105 
106  if (ilSession::_exists($a_session_id))
107  {
108  $ilDB->update("usr_session", $fields,
109  array("session_id" => array("text", $a_session_id)));
110  }
111  else
112  {
113  $fields["session_id"] = array("text", $a_session_id);
114  $fields["createtime"] = array("integer", $now);
115 
116  $ilDB->insert("usr_session", $fields);
117 
118  // check type against session control
119  $type = $fields["type"][1];
121  {
122  ilSessionStatistics::createRawEntry($fields["session_id"][1],
123  $type, $fields["createtime"][1], $fields["user_id"][1]);
124  }
125  }
126 
127  // finally delete deprecated sessions
128  if(rand(0, 50) == 2)
129  {
130  // get time _before_ destroying expired sessions
131  self::_destroyExpiredSessions();
133  }
134 
135  return true;
136  }
< 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']
$GLOBALS['ct_recipient']
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.
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 388 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().

389  {
390  unset($_SESSION[$a_var]);
391  }
< 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:

◆ get()

static ilSession::get (   $a_var)
static

Get a value.

Parameters

Definition at line 377 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().

378  {
379  return $_SESSION[$a_var];
380  }
< 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 408 of file class.ilSession.php.

409  {
410  return self::$closing_context;
411  }

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

References $ilSetting, and ilSessionControl\DEFAULT_MAX_IDLE.

282  {
283  global $ilSetting;
284 
285  if( $fixedMode || $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED )
286  {
287  // fixed session
288  return time() + ini_get('session.gc_maxlifetime');
289  }
290  else if( $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT )
291  {
292  // load dependent session settings
293  return time() + (int) ($ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE) * 60);
294  }
295  }
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 307 of file class.ilSession.php.

References $ilSetting, and ilSessionControl\DEFAULT_MAX_IDLE.

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

308  {
309  global $ilSetting, $ilClientIniFile;
310 
311  if( $fixedMode || $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_FIXED )
312  {
313  // fixed session
314  return $ilClientIniFile->readVariable('session','expire');
315  }
316  else if( $ilSetting->get('session_handling_type', self::SESSION_HANDLING_FIXED) == self::SESSION_HANDLING_LOAD_DEPENDENT )
317  {
318  // load dependent session settings
319  return (int) ($ilSetting->get('session_max_idle', ilSessionControl::DEFAULT_MAX_IDLE) * 60);
320  }
321  }
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 332 of file class.ilSession.php.

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

333  {
334  return self::getIdleValue(true);
335  }
+ Here is the caller graph for this function:

◆ set()

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

Set a value.

Parameters

Definition at line 366 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().

367  {
368  $_SESSION[$a_var] = $a_val;
369  }
< 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 398 of file class.ilSession.php.

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

399  {
400  self::$closing_context = (int)$a_context;
401  }
+ 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.

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