ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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:$

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

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
203
204 $ilDB->manipulate($q);
205
206 return true;
207 }
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(), ilInitialisation\authenticate(), ilSessionDBHandler\destroy(), ilInitialisation\initUser(), ilSessionControl\kickFirstRequestAbidencer(), ilSessionControl\kickOneMinIdleSession(), ilStartUpGUI\migrateAccount(), 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 214 of file class.ilSession.php.

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 }

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

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 }
static _destroy($a_session_id, $a_closing_context=null, $a_expired_at=null)
Destroy session.

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

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.

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

Referenced by ilContainer\cloneAllObject(), 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 154 of file class.ilSession.php.

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 }

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.

Parameters
stringsession id
Returns
string session data

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

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 }

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

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

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

◆ _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.

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
141 }
142
143 return true;
144 }
$_SESSION["AccountId"]
static createRawEntry($a_session_id, $a_session_type, $a_timestamp, $a_user_id)
Create raw data entry.
static _exists($a_session_id)
Check whether session exists.
static _destroyExpiredSessions()
Destroy expired sessions.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

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

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

434 {
435 self::$enable_web_access_without_session = (bool)$enable_web_access_without_session;
436 }
static $enable_web_access_without_session

References $enable_web_access_without_session.

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

+ Here is the caller graph for this function:

◆ get()

static ilSession::get (   $a_var)
static

Get a value.

Parameters

return

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

387 {
388 return $_SESSION[$a_var];
389 }

References $_SESSION.

Referenced by ilMailFolderGUI\addSubfolderCommands(), ilPersonalSettingsGUI\allowPasswordChange(), ilObjectGUI\confirmedDeleteObject(), ilMailGUI\executeCommand(), ilTemplate\fillMessage(), ilHelpMappingTableGUI\getChapters(), ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilAwarenessGUI\getMainMenuHTML(), ilMailFormCall\getRecipients(), ilMailFormCall\getRefererRedirectUrl(), ilMailFormCall\getSignature(), ilMailMemberSearchGUI\getStoredReferer(), ilObjUser\hasToAcceptTermsOfServiceInSession(), ilInitialisation\initCore(), ilHelpGUI\initHelp(), ilObjForumGUI\initSessionStorage(), ilMailFormCall\isRefererStored(), ilTestPlayerAbstractGUI\isTestSignRedirectRequired(), ilStartUpGUI\migrateAccount(), ilAwarenessAct\notifyOnNewOnlineContacts(), ilMailFolderGUI\performAddSubFolder(), ilMailFolderGUI\performRenameSubFolder(), ilPersonalSettingsGUI\savePassword(), ilPersonalProfileGUI\savePersonalData(), ilHelpGUI\search(), ilMailFormCall\setContextId(), ilMailFormCall\setContextParameters(), ilMailFormCall\setRecipients(), ilTemplate\show(), ilObjContentObjectGUI\showExportIDsOverview(), ilMailGUI\showHeader(), ilHelpGUI\showHelp(), 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 417 of file class.ilSession.php.

418 {
420 }

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

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

References $ilSetting, and ilSessionControl\DEFAULT_MAX_IDLE.

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

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 }

References $ilSetting, and ilSessionControl\DEFAULT_MAX_IDLE.

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

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

342 {
343 return self::getIdleValue(true);
344 }
static getIdleValue($fixedMode=false)
Returns the idle time in seconds.

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

426 {
428 }

References $enable_web_access_without_session.

◆ set()

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

408 {
409 self::$closing_context = (int)$a_context;
410 }

Referenced by ilSessionControl\checkCurrentSessionIsAllowed(), ilPersonalSettingsGUI\deleteOwnAccountLogout(), ilInitialisation\goToLogin(), ilInitialisation\goToPublicSection(), 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

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: