To insert additional logic when a user logs off one might look at function user_logout() in user.pages.inc. This code being in a core module, you should not edit it, but works very well... for example by adding the following code to the top of the 'user_logout()' function...

$last_run = variable_get('cron_last', 0);  
if(time() - $last_run > 86400) {  
    include_once './includes/bootstrap.inc';  
    watchdog('user', 'cron set to run and cache to be cleared on user logout', array('%name' => $user->name));  

... I get the cache cleared and cron run if cron has not run in the last 24 hrs. Okay, not ideal for cron but that's another issue.

Where is the best place to add this little snippet? I could simply implement my own logout menu item... but I'm not keen on that solution.

Thanks in advance.


2 Answers 2


Instead of modifying core, you can implement hook_user() in a custom module. Then you can check the $op parameter to see if it equals "logout". This code will run whenever a user logs out, regardless of what menu item or link they click to log out.

Note that this is different between Drupal 6 and 7. This question was tagged Drupal 6, but if you're using Drupal 7, or plan to later, be aware that this hook was replaced with hook_user_logout().

  • I had yet to write my first module. I'd been putting if off 'til I needed one. So, I read up on it and implemented this so very simple module. Thanks.
    – clsturgeon
    Commented Mar 6, 2011 at 2:23
  • I've implemented this into a module called "Logout Redirect" only for 6.x at the moment.
    – oranges13
    Commented Sep 7, 2011 at 18:10

Might want to check out the Poor Mans Cron module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.