How to programmatically log out a user in Drupal 7?
11,575
Solution 1
You should call user_logout()
.
Solution 2
use this any where
<?php
module_load_include('pages.inc', 'user');
user_logout();
?>
Solution 3
Another option is using the Rules module. You can set a rule up to redirect to a URL after a user logs out and various other rules if needed.
http://drupal.org/project/rules
Author by
jini
Updated on July 28, 2022Comments
-
jini over 1 year
I need to log a user out and redirect to a URL.
How would I do that in Drupal 7?
Thanks
-
Clive about 12 years+1 and then
drupal_goto()
-
J-P almost 11 yearsuser_logout() in D6 and D7 finish with their own drupal_goto(). I'm not convinced that your own call after that point would be processed.
-
artfulrobot over 7 yearsNot clear how this answers 2nd part of Q: how to redirect to a URL after logging out, since in D7
drupal_goto()
callsuser_logout()
anyway.