How do I delete cookies when users log out? How can I do this with out modifying any core module?
-
1Stupid 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– BerdirJan 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 .– KTMJan 9, 2017 at 8:05
1 Answer
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');
}
-
-
1That is the user object on which the operation was just performed. For example the uid is
$account->id()
. 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 ?– KTMJan 9, 2017 at 8:00
-
-