1

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 Jan 6 '17 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 . – Crazyrubixfan Jan 9 '17 at 8:05
4

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

For example:

function mymodule_user_logout($account) {
  user_cookie_delete('name');
  user_cookie_delete('mail');
  user_cookie_delete('homepage');
}
  • What is $account in this ? – Crazyrubixfan Jan 9 '17 at 7:54
  • 1
    That is the user object on which the operation was just performed. For example the uid is $account->id(). – Wim Mostrey Jan 9 '17 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 ? – Crazyrubixfan Jan 9 '17 at 8:00
  • I added sample code to my answer. – Wim Mostrey Jan 9 '17 at 8:08
  • Is there a similar method that would work on Drupal 7? – Christia Jan 11 '17 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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