You are here

function session_limit_page in Session Limit 5

Same name and namespace in other branches
  1. 6.2 session_limit.module \session_limit_page()
  2. 6 session_limit.module \session_limit_page()
  3. 7.2 session_limit.module \session_limit_page()

Display/Delete sessions..

1 string reference to 'session_limit_page'
session_limit_menu in ./session_limit.module
Implementation of hook_menu(). Redirect user if over session limit.

File

./session_limit.module, line 126
Established Sessions do NOT need to verify every page load. new Session must deal w/ determining which connection is cut.

Code

function session_limit_page() {
  global $user;
  if (!$user->uid > 0) {
    drupal_goto();
  }
  if (variable_get('session_limit_auto_drop', 0)) {

    // Get the oldest session.
    $sid = db_result(db_query_range("SELECT sid FROM {sessions} WHERE uid = %d ORDER BY timestamp", $user->uid, 0, 1));
    if ($sid) {
      _session_limit_disconnect($sid);
    }
    drupal_goto();
  }
  $result = db_query('SELECT * FROM {sessions} WHERE uid = %d', $user->uid);
  while ($obj = db_fetch_object($result)) {
    if ($user->sid == $obj->sid) {
      $message = t('Your current session.');
    }
    else {
      unset($message);
    }
    $sids[$obj->sid] = t('<strong>Host:</strong> %host (idle: %time) <b>@message</b>', array(
      '%host' => $obj->hostname,
      '@message' => $message,
      '%time' => format_interval(time() - $obj->timestamp),
    ));
  }
  $form['sid'] = array(
    '#type' => 'radios',
    '#title' => t('Select a session to disconnect'),
    '#options' => $sids,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Disconnect'),
  );
  return $form;
}