8

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

How would I do that in Drupal 7?

Thanks

Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169

3 Answers3

18

You should call user_logout().

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • 2
    +1 and then [`drupal_goto()`](http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_goto/7) – Clive Mar 30 '12 at 20:20
  • 2
    user_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. – J-P May 22 '13 at 14:14
  • Not clear how this answers 2nd part of Q: how to redirect to a URL after logging out, since in D7 `drupal_goto()` calls `user_logout()` anyway. – artfulrobot Aug 15 '16 at 06:49
6

use this any where

 <?php
module_load_include('pages.inc', 'user');
user_logout();
?>
2

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

chadpeppers
  • 2,057
  • 1
  • 20
  • 27