How do I delete cookies when users log out? How can I do this with out modifying any core module?

  • 1
    Stupid question, but why not use session then you store your data? Or if you need it as a way to transport infos to the browser (for JS), then you might want to use drupalSettings instead. Cookies have to be sent with every request made to your server
    – Berdir
    Commented Jan 6, 2017 at 17:19
  • The problem is that not saving to a session and destroy it on logut , the problem is i cant identify the user is loged out or not in a custom php file inside a module . The session is not getting there . So i am using cookies to identiy the user logged in or not in the custom file inside the module folder .
    – KTM
    Commented Jan 9, 2017 at 8:05

1 Answer 1


Imlement hook_user_logout($account) and call user_cookie_delete($cookie_name).

For example:

function mymodule_user_logout($account) {
  • What is $account in this ?
    – KTM
    Commented Jan 9, 2017 at 7:54
  • 1
    That is the user object on which the operation was just performed. For example the uid is $account->id(). Commented Jan 9, 2017 at 7:56
  • can u place a sample code using that function so that users can understand easily , my doubt is from where $account is come from ?
    – KTM
    Commented Jan 9, 2017 at 8:00
  • I added sample code to my answer. Commented Jan 9, 2017 at 8:08
  • Is there a similar method that would work on Drupal 7?
    – Christia
    Commented Jan 11, 2017 at 7:34

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.