Created
November 14, 2012 08:22
-
-
Save junaidpv/4070975 to your computer and use it in GitHub Desktop.
Drupal 7 CLI script to logout all users and clear sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you for sharing