Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically log out a user in Drupal 7?

I need to log a user out and redirect to a URL.

How would I do that in Drupal 7?

Thanks

like image 569
jini Avatar asked Mar 30 '12 18:03

jini


3 Answers

You should call user_logout().

like image 57
ceejayoz Avatar answered Oct 21 '22 02:10

ceejayoz


use this any where

 <?php
module_load_include('pages.inc', 'user');
user_logout();
?>
like image 6
Bhanu Prakash Ryaga Avatar answered Oct 21 '22 02:10

Bhanu Prakash Ryaga


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

like image 2
chadpeppers Avatar answered Oct 21 '22 03:10

chadpeppers