I'd like to be able to provide the URL end users will reach after logging out instead of my domain being the default and only option www.mysite.com

Comments

francewhoa’s picture

With Drupal 5.7 adapt then use the following link:

http://www.example.com/logout&destination=node/mylogoutpage

This link do a log out then redirect to the page "mylogoutpage".

On your site, replace "www.example.com" with your domain and change the "node/mylogoutpage" with the path of your goodbye page.

If you use menus disable the default "logout" link in Admin --> Menus and then manually create a link somewhere on your site that uses the above link.

Source: http://drupal.org/node/120253

tcconway’s picture

Version: 5.4 » 5.7

This feature doesn't accept third party urls. I'd like to do something like:
http://www.example.com/logout?destination=http://www.another-site.com/?v...

Possible? when I try that example on my site, It just goes to http://www.example.com/www.another-site...etc

Any ideas?
Thanks!

sid3000’s picture

modify the drupal_goto() function!

tcconway’s picture

Thanks sid. I'll have a look.

One more question, if you don't mind:
Is there a way to set up a custom logout? Not my altering core, but maybe in template.php or something?

I'd like to do a bit of php code during the logout process. My install ties into a custom login process, and when a user clicks a logout link, I have to do a couple of database calls, update a few session variables in addition to logging out of drupal.

Any way to have a custom function somewhere, where I could do something like this, without altering core?
TIA

sid3000’s picture

abramo’s picture

May be you want to try the following code, simple and effective:

<?php
print l('Log out', 'logout', array('class' => 'logout-link'), 'destination=_your_destination_here_', NULL, TRUE);
?>

Many thanks to Nils (suit4) who provided the code.

.

willmoy’s picture

Title: Custom logout redirects » Custom logout redirects to external sites
Version: 5.7 » 7.x-dev

You can get a logout to redirect to a page on your site without any code. In D7 enable menu module, go to admin/structure/menu, and in the user menu disable the logout link, and replace with a custom link to user/logout?destination=node/10 or whatever.

However, if you wish this to redirect to an external site, no dice. user_logout() calls drupal_goto() which only redirects internally.

Therefore, valid feature request. The open redirect concern doesn't apply here because you have to be logged in to reach user/logout.

But, this request depends on drupal_goto supporting external urls #337261: parse_url in drupal_goto breaks destination url.

canyonbreeze’s picture

Here is what I did that seems to work. Create a page using input format php and put in the following code. Assign the menu link to the page before saving. When you save the page you are logged out so you will have to re-login. I have to delete the page and recreate it to edit is well or it logs out before I can edit. No big deal I just keep the code in a text file.

[code]

  global $user;

  watchdog('user', 'Session closed for %name.', array('%name' => $user->name));

  // Eat the cookies
  foreach($_COOKIE AS $key => $value)
  {
    setcookie($key,$value,1);
    unset($_COOKIE[$key]);
  }

  // Destroy the current session:
  session_destroy();
  $_SESSION = array();

  // Only variables can be passed by reference workaround.
  $null = NULL;
  user_module_invoke('logout', $null, $user);

  // Load the anonymous user
  $user = drupal_anonymous_user();

header('Cache-Control: no-cache');
header('Expires: -1');
header('Location: http://where_ever.com');

[/code]

canyonbreeze’s picture

This board messed up the last line trying to resolve the link or something. See php headers command for proper syntax. This doesn't seem to clear out the cache correctly on all browsers so needs some work.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.