I would like to have a button/menu item/block with link (it doesn't matter) that (when clicked) the user would be redirected to an external URL and at same time it would log out from my site. I don't want this to affect the regular logout link.
How can I achive this?
Thank's in advance.

Comments

mcfilms’s picture

+1

You can use the site.com/logout url to log out the current user... but directing them to a specific url would be nice when you "show them the door." So I don't have a solution, but I hope someone does.

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

Anonymous’s picture

Hi, you need to implement hook_user in your module, then check for the "logout" operation. In the case of a logout, do a drupal_goto() to an external URL.

Anonymous’s picture

Ok, I read your question again. You need to set up a URL with hook_menu. In the function called by the url, put
the following code:

  global $user;
  session_destroy();
  user_module_invoke('logout', NULL, $user);

  // Load the anonymous user
  $user = drupal_anonymous_user();
  drupal_goto("http://goodbye.com");
bsenftner’s picture

Wow. that's gotta be one of the most useful snippets / answers to a forum question I've seen.

mcfilms’s picture

Just saying this seems like it would be a useful and easy-to-create module. The UI in Drupal would simply be two fields:
• What local url would you like to use for your logout?
• What url would you like to have the logged out user re-directed to?

I have ALMOST enough skill to build this module. If someone comes across this thread in six months and "Logout Destination" does not yet exist, please resurrect it. By then I will be ready to build this module.

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

asb’s picture

A year has passed, and still no "Logout Destination" module seems to exist.

Anyone care to write one? ;-)

margaridacarvalho’s picture

Thank you all so much for your interest.
But I do no master drupal programming. How can I set up a URL with hook_menu? Where should I put that code?