Skip to content

Instantly share code, notes, and snippets.

@junaidpv
Created November 14, 2012 08:22
Show Gist options
  • Select an option

  • Save junaidpv/4070975 to your computer and use it in GitHub Desktop.

Select an option

Save junaidpv/4070975 to your computer and use it in GitHub Desktop.
Drupal 7 CLI script to logout all users and clear sessions
<?php
// Bootstrap
// Change chdir to the full path of your Drupal root
define('DRUPAL_ROOT', getcwd());
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
$_SERVER['REMOTE_ADDR'] = "127.0.0.1";
$_SERVER['REQUEST_METHOD'] = NULL;
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$query = db_select('sessions', 's');
$query->fields('s', array('uid', 'sid'));
$result = $query->execute();
while($s = $result->fetch()) {
$u = user_load($s->uid);
module_invoke_all('user_logout', $u);
db_delete('sessions')
->condition('sid', $s->sid)
->execute();
}
@paraacha
Copy link
Copy Markdown

thank you for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment