Drupal 7 logout functionality

xarzu's picture

They have: 25 posts

Joined: May 2007

Hello Forum.

I am using Drupal 7 on a new web site. It uses a theme from devsaran. I am not going to mention where the web site is because I have told the friend whom I am making the site for that we will keep the location private until it is completed.

I have created a test user and I logged on to the site. Now, here is the weird part. I did not grant the user any special privileges, but, still, the user does not seem to be able to do anything once he logs in. Granted, there are not any pages posted yet so, I suppose, he might be able to make comments. Is that all a new user can do?

Here is the problem I have. There is no functionality for him to log out. How would a new user log out?

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

Why are you creating a new site on Drupal 7 right now? Drupal 8 is viable for most common situations right now, and you'll save yourself a lot of upgrade headaches later on by starting with 8.

Users don't have any privileges unless you grant them. What you probably want to do is create a new role, assign it it some permissions, and then give that user account the new role. You can also assign some privileges to the default "Authenticated User" role.

This User Guide page on "Managing User Accounts" should help:


There should be a menu link to log out. If there isn't, it might be because you haven't placed the User Account menu into the theme anywhere. Try going to the Admin > Structure > blocks menu and adding the User Account menu to a region.

They have: 11 posts

Joined: Aug 2016

Thank you for writing in details about this function. i have recently started development in drupal project so, i was not aware about drupal project.

isarbjitgrewal's picture

They have: 8 posts

Joined: May 2017

Here is the improved solution for Drupal 7 logout functionality.

function user_logout($message = '', $status = 'warning') {
  global $user;

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

  module_invoke_all('user_logout', $user);

  // Destroy the current session, and reset $user to the anonymous user.

// Sends a message to the user if you have a need to warn you
      drupal_set_message($message, $status);

He has: 7 posts

Joined: Apr 2021

Megan, once I also had this problem. Thanks for sharing such useful information.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.