38 'session_max_idle_after_first_request',
39 'session_allow_client_maintenance',
40 'session_handling_type'
60 self::SESSION_TYPE_USER,
61 self::SESSION_TYPE_ANONYM
71 self::SESSION_TYPE_UNKNOWN,
72 self::SESSION_TYPE_SYSTEM,
73 self::SESSION_TYPE_ADMIN
90 if( $ilSetting->get(
'session_handling_type', 0) != 1 )
100 if(!$ilSetting->get(
"pub_section"))
114 self::debug(
'Browser sent sid cookie with value ('.$sid.
')');
118 self::debug(
'remove session cookie for ('.$sid.
') and trigger event');
123 global $ilAppEventHandler;
124 $ilAppEventHandler->raise(
125 'Services/Authentication',
'expiredSessionDetected', array()
143 if( $ilSetting->get(
'session_handling_type', 0) != 1 )
167 if( $ilSetting->get(
'session_handling_type', 0) != 1 )
175 case isset($_ENV[
'SHELL']):
187 case $user_id == ANONYMOUS_USER_ID:
211 if( $ilSetting->get(
'session_handling_type', 0) != 1 )
236 if($max_sessions > 0)
241 self::debug(__METHOD__.
"--> total existing sessions (".$num_sessions.
")");
243 if(($num_sessions + 1) > $max_sessions)
245 self::debug(__METHOD__.
' --> limit for session pool reached, but try kicking some first request abidencer');
252 if(($num_sessions + 1) > $max_sessions)
254 self::debug(__METHOD__.
' --> limit for session pool still reached so try kick one min idle session');
261 if(($num_sessions + 1) > $max_sessions)
263 self::debug(__METHOD__.
' --> limit for session pool still reached so logout session ('.session_id().
') and trigger event');
268 global $ilAppEventHandler;
269 $ilAppEventHandler->raise(
270 'Services/Authentication',
'reachedSessionPoolLimit', array()
277 self::debug(__METHOD__.
' --> limit of session pool not reached anymore after kicking one min idle session');
282 self::debug(__METHOD__.
' --> limit of session pool not reached anymore after kicking some first request abidencer');
287 self::debug(__METHOD__.
' --> limit for session pool not reached yet');
292 self::debug(__METHOD__.
' --> limit for session pool not set so check is bypassed');
309 $query =
"SELECT count(session_id) AS num_sessions FROM usr_session ".
310 "WHERE expires > %s ".
311 "AND ".$ilDB->in(
'type', $a_types,
false,
'integer');
313 $res = $ilDB->queryF(
$query, array(
'integer'), array($ts));
316 return $row->num_sessions;
333 $min_idle = (int)$ilSetting->get(
'session_min_idle', self::DEFAULT_MIN_IDLE) * 60;
334 $max_idle = (int)$ilSetting->get(
'session_max_idle', self::DEFAULT_MAX_IDLE) * 60;
336 $query =
"SELECT session_id FROM usr_session WHERE expires >= %s " .
337 "AND (expires - %s) < (%s - %s) " .
338 "AND ".$ilDB->in(
'type', $a_types,
false,
'integer');
341 $res = $ilDB->queryF(
343 array(
'integer',
'integer',
'integer',
'integer'),
344 array($ts, $ts, $max_idle, $min_idle)
349 $sid =
$row->session_id;
352 self::debug(__METHOD__.
' --> successfully deleted one min idle session');
357 self::debug(__METHOD__.
' --> no min idle session available for deletion');
372 $max_idle_after_first_request = (int)$ilSetting->get(
'session_max_idle_after_first_request') * 60;
374 if((
int)$max_idle_after_first_request == 0)
return;
376 $query =
"DELETE FROM usr_session WHERE " .
377 "(ctime - createtime) < %s " .
378 "AND (%s - createtime) > %s " .
379 "AND ".$ilDB->in(
'type', $a_types,
false,
'integer');
381 $ilDB->manipulateF(
$query,
382 array(
'integer',
'integer',
'integer'),
383 array($max_idle_after_first_request, time(), $max_idle_after_first_request)
386 self::debug(__METHOD__.
' --> Finished kicking first request abidencer');
402 $query =
"SELECT session_id, expires FROM usr_session ".
403 "WHERE session_id = %s";
405 $res = $ilDB->queryF(
$query, array(
'text'), array($a_sid));
411 while(
$row = $ilDB->fetchAssoc(
$res) )
413 if(
$row[
'expires'] > $ts )
415 self::debug(__METHOD__.
' --> Found a valid session with id ('.$a_sid.
')');
420 self::debug(__METHOD__.
' --> Found an expired session with id ('.$a_sid.
')');
424 if(count($sessions) == 1)
426 self::debug(__METHOD__.
' --> Exact one valid session found for session id ('.$a_sid.
')');
433 self::debug(__METHOD__.
' --> Strange!!! More than one sessions found for given session id! ('.$a_sid.
')');
434 else self::debug(__METHOD__.
' --> No valid session found for session id ('.$a_sid.
')');
459 if( !(
int)$a_user_id )
return false;
463 $access = $rbacsystem->checkAccessOfUser(
464 $a_user_id,
'read,visible', SYSTEM_FOLDER_ID
476 private static function debug($a_debug_log_message)
480 if(DEVMODE) $ilLog->write($a_debug_log_message,
'message');
482 if(self::INTERNAL_DEBUG) error_log($a_debug_log_message.
"\n", 3,
'session.log');