function session_limit_invoke_session_limit in Session Limit 6.2
Same name and namespace in other branches
- 6 session_limit.module \session_limit_invoke_session_limit()
- 7.2 session_limit.module \session_limit_invoke_session_limit()
Limit a users access to the sites based on the current session.
Parameters
string $session: The session id string which identifies the current session.
string $op: The action which caused the session limitation event. This is either 'collision' or 'disconnect'.
Return value
array The results of all hook_session_limit functions. Note that in a collision event, a Drupal goto is executed so this function does not return.
2 calls to session_limit_invoke_session_limit()
- session_limit_init in ./
session_limit.module - Implementation of hook_init().
- session_limit_page_submit in ./
session_limit.module - Handler for submissions from session_limit_page().
File
- ./
session_limit.module, line 548 - Limits multiple sessions per user.
Code
function session_limit_invoke_session_limit($session, $op) {
$return = array();
// Execute the hook_session_limit().
foreach (module_implements('session_limit') as $name) {
$function = $name . '_session_limit';
$result = $function($session, $op);
if (isset($result) && is_array($result)) {
$return = array_merge($return, $result);
}
elseif (isset($result)) {
$return[] = $result;
}
}
// In the event of a collision, close oldest sessions.
if ($op == 'collision') {
if (variable_get('session_limit_behaviour', SESSION_LIMIT_DO_NOTHING) == SESSION_LIMIT_DROP) {
global $user;
// Get the number of sessions that should be removed.
$count = db_result(db_query("SELECT COUNT(DISTINCT(sid)) FROM {sessions} WHERE uid = %d", $user->uid));
$limit = $count - session_limit_user_max_sessions($user);
if ($limit > 0) {
$result = db_query_range("SELECT DISTINCT(sid) as sid FROM {sessions} WHERE uid = %d ORDER BY timestamp", $user->uid, 0, $limit);
while ($sids = db_fetch_object($result)) {
session_limit_invoke_session_limit($sids->sid, 'disconnect');
}
}
}
else {
drupal_goto('session/limit');
}
}
return $return;
}