After logging out you're redirected to home page I don't like it, instead I wanna stay at the same page at which I pressed "log-out" button (I'm using 403 redirect to home so in case access denied error it will have no impact on user), how achieve this?

Comments

WorldFallz’s picture

Try setting up a core trigger and action for it.

anrikun’s picture

<?php
function MYMODULE_user($op, &$edit, &$account, $category = NULL) {
  global $user;

  if ($op == 'logout') {
    // Load the anonymous user
    $user = drupal_anonymous_user();
    
    drupal_goto(referer_uri());
  }
}
?>
v8powerage’s picture

Thank You v. much ;-)

thorshammer’s picture

... if referer_uri() is not a page that an anomymous user is authorized to access?

WorldFallz’s picture

then you'll get access denied.

jghyde’s picture

Here's the Cliff's Notes on how to make a module to make the user stay on the same page after logout. It takes 5 minutes, max.

Prerequisites: Drupal 6 and no other modules named 'stayafterlogout' in your sites/all/modules directory (99.998% of you will not).

Our module name will be 'stayafterlogout'. You can name your module anything, but make sure you change all the terms, functions, variables as appropriate to your own name in the directions below. In a hurry? Keep the same module name, 'stayafterlogout' and this is just a copy-paste endeavor.

  1. Create a directory called sites/all/modules/stayafterlogout
  2. Create a blank file, and name it after the module. It should be here sites/all/modules/stayafterlogout/stayafterlogout.module
  3. Make the contents of stayafterlogout.module exactly this:
    <?php
    // $Id$
    
    /**
    * Valid permissions for this module
    * @return array An array of valid permissions for the onthisdate module
    */
    function stayafterlogout_perm() {
      return array('Allow user to stay on the same page after logout');
    } // function stayafterlogout_perm()
    
    /**
    * Re-aim the user to the same page after logout
    * no @return array. This just does stuff.
    */
    
    
    function stayafterlogout_user($op, &$edit, &$account, $category = NULL) {
      global $user;
    
      if ($op == 'logout') {
        // Load the anonymous user
        $user = drupal_anonymous_user();
        drupal_goto(referer_uri());
      }
    } // function stayafterlogout_user()
    ?>
    

    NOTE!: Do not include the final, closing '?>' tag. I placed it here on this page for text formatting purposes. See http://drupal.org/node/206754 for details.

  4. Create another blank file, and name it for the module's info page. It should be here sites/all/modules/stayafterlogout/stayafterlogout.info
  5. Make the contents of stayafterlogout.info exactly this:
    ; $Id$
    name = Stay After Logout
    description = When enabled, it will leave the user on the same page the logout click was accessed after a user logout process is complete.
    core = 6.x
    package = "Authentication"
    
  6. Inside of your sites/all/modules/stayafterlogin folder you should now have your complete module, named appropriately, 'Stay After Logout', with two files:
    dir sites/all/modules/stayafterlogout
    stayafterlogout.info
    stayafterlogout.module
  7. With your Web browser, go to the /admin/build/modules page and enable the stayafterlogout module
  8. Test and rejoice

Thanks @WorldFallz for the info.

Joe Hyde
http://www.hydeinteractive.com/

Local News Platform Built on Drupal
http://sanangelolive.com/

anrikun’s picture

Nice Howto Joe :-)
You can remove the stayafterlogout_perm() function from the code as it's unused (and useless) here.

fehin’s picture

subscribing

asb’s picture

On my site, Drupal 6.20 is behaving differently. After logging out, the user stays on the page where he was before and gets an "Access denied" message. We would like to avoid this error message and redirect the user on logout to the frontpage. Sadly, Drupal core's actions/triggers do not allow this.

Any ideas?

v8powerage’s picture

You may point 403 / 404 pages to "home" at /admin/settings/error-reporting

aks_richa’s picture

Thanks you so much.. you save my time... its worked for me... :)