| 5 user.module | user_logout() |
| 6 user.pages.inc | user_logout() |
| 7 user.pages.inc | user_logout() |
| 8 user.pages.inc | user_logout() |
Menu callback; logs the current user out, and redirects to the home page.
1 call to user_logout()
5 string references to 'user_logout'
File
- modules/
user/ user.pages.inc, line 167 - User page callback file for the user module.
Code
function user_logout() {
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.
session_destroy();
drupal_goto();
}
Login or register to post comments
Comments
Call to undefined function user_logout()
How can i call this in my template.php file?
I want to automatically log out user if they use that theme.
Suggestion
Greetings.
I have a suggestion for improvement for this function.
Soon after the session_destroy (), could be placed a drupal_set_message () to warn the user of the reason for the logout.
Would be as follows:
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.
session_destroy();
// Sends a message to the user if you have a need to warn you
if(!empty($message)){
drupal_set_message($message, $status);
}
drupal_goto();
}
Why is this suggestion?
When I'm using hook_user_login and for some reason need to kill the session user can not I put after user_logout drupal_set_message () why there is a drupal_goto () and also no point in putting before why there is a session.destroy () which kills with the entire session.
The only way I saw to solve this is after putting session.destroy ().
[]'s
I have an imporovment on this function
I have an imporovment on this function, why not have a paramater with default value to indicate where to go after the logout.
<?php
function user_logout($destination = '') {
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.
session_destroy();
drupal_goto($destination);
}
?>
improvement suggestion
i agree with artofeclipse, but the destination should be provided by the hook, so it should be possible to interact and change the destination by changing the destination and the user_logout function redirects to this destination
Couldn't you just
Couldn't you just do...
mymodule_user_logout($account) {$_GET['destination'] = 'path/to/redirect/to/after/logout';
}