38 'session_max_idle_after_first_request',
39 'session_allow_client_maintenance'
59 self::SESSION_TYPE_USER,
60 self::SESSION_TYPE_ANONYM
70 self::SESSION_TYPE_UNKNOWN,
71 self::SESSION_TYPE_SYSTEM,
72 self::SESSION_TYPE_ADMIN
89 if( $ilSetting->get(
'session_handling_type', 0) != 1 )
99 if(!$ilSetting->get(
"pub_section"))
113 self::debug(
'Browser sent sid cookie with value ('.$sid.
')');
117 self::debug(
'remove session cookie for ('.$sid.
') and trigger event');
122 global $ilAppEventHandler;
123 $ilAppEventHandler->raise(
124 'Services/Authentication',
'expiredSessionDetected', array()
142 if( $ilSetting->get(
'session_handling_type', 0) != 1 )
166 if( $ilSetting->get(
'session_handling_type', 0) != 1 )
174 case isset($_ENV[
'SHELL']):
186 case $user_id == ANONYMOUS_USER_ID:
210 if( $ilSetting->get(
'session_handling_type', 0) != 1 )
235 if($max_sessions > 0)
240 self::debug(__METHOD__.
"--> total existing sessions (".$num_sessions.
")");
242 if(($num_sessions + 1) > $max_sessions)
244 self::debug(__METHOD__.
' --> limit for session pool reached, but try kicking some first request abidencer');
251 if(($num_sessions + 1) > $max_sessions)
253 self::debug(__METHOD__.
' --> limit for session pool still reached so try kick one min idle session');
260 if(($num_sessions + 1) > $max_sessions)
262 self::debug(__METHOD__.
' --> limit for session pool still reached so logout session ('.session_id().
') and trigger event');
267 global $ilAppEventHandler;
268 $ilAppEventHandler->raise(
269 'Services/Authentication',
'reachedSessionPoolLimit', array()
276 self::debug(__METHOD__.
' --> limit of session pool not reached anymore after kicking one min idle session');
281 self::debug(__METHOD__.
' --> limit of session pool not reached anymore after kicking some first request abidencer');
286 self::debug(__METHOD__.
' --> limit for session pool not reached yet');
291 self::debug(__METHOD__.
' --> limit for session pool not set so check is bypassed');
308 $query =
"SELECT count(session_id) AS num_sessions FROM usr_session ".
309 "WHERE expires > %s ".
310 "AND ".$ilDB->in(
'type', $a_types,
false,
'integer');
312 $res = $ilDB->queryF(
$query, array(
'integer'), array($ts));
315 return $row->num_sessions;
332 $min_idle = (int)$ilSetting->get(
'session_min_idle', self::DEFAULT_MIN_IDLE) * 60;
333 $max_idle = (int)$ilSetting->get(
'session_max_idle', self::DEFAULT_MAX_IDLE) * 60;
335 $query =
"SELECT session_id FROM usr_session WHERE expires >= %s " .
336 "AND (expires - %s) < (%s - %s) " .
337 "AND ".$ilDB->in(
'type', $a_types,
false,
'integer');
340 $res = $ilDB->queryF(
342 array(
'integer',
'integer',
'integer',
'integer'),
343 array($ts, $ts, $max_idle, $min_idle)
348 $sid =
$row->session_id;
351 self::debug(__METHOD__.
' --> successfully deleted one min idle session');
356 self::debug(__METHOD__.
' --> no min idle session available for deletion');
371 $max_idle_after_first_request = (int)$ilSetting->get(
'session_max_idle_after_first_request') * 60;
373 if((
int)$max_idle_after_first_request == 0)
return;
375 $query =
"DELETE FROM usr_session WHERE " .
376 "(ctime - createtime) < %s " .
377 "AND (%s - createtime) > %s " .
378 "AND ".$ilDB->in(
'type', $a_types,
false,
'integer');
380 $ilDB->manipulateF(
$query,
381 array(
'integer',
'integer',
'integer'),
382 array($max_idle_after_first_request, time(), $max_idle_after_first_request)
385 self::debug(__METHOD__.
' --> Finished kicking first request abidencer');
401 $query =
"SELECT session_id, expires FROM usr_session ".
402 "WHERE session_id = %s";
404 $res = $ilDB->queryF(
$query, array(
'text'), array($a_sid));
410 while(
$row = $ilDB->fetchAssoc(
$res) )
412 if(
$row[
'expires'] > $ts )
414 self::debug(__METHOD__.
' --> Found a valid session with id ('.$a_sid.
')');
419 self::debug(__METHOD__.
' --> Found an expired session with id ('.$a_sid.
')');
423 if(count($sessions) == 1)
425 self::debug(__METHOD__.
' --> Exact one valid session found for session id ('.$a_sid.
')');
432 self::debug(__METHOD__.
' --> Strange!!! More than one sessions found for given session id! ('.$a_sid.
')');
433 else self::debug(__METHOD__.
' --> No valid session found for session id ('.$a_sid.
')');
458 if( !(
int)$a_user_id )
return false;
462 $access = $rbacsystem->checkAccessOfUser(
463 $a_user_id,
'read,visible', SYSTEM_FOLDER_ID
475 private static function debug($a_debug_log_message)
479 if(DEVMODE) $ilLog->write($a_debug_log_message,
'message');
481 if(self::INTERNAL_DEBUG) error_log($a_debug_log_message.
"\n", 3,
'session.log');