离开页面时死亡的Cookie

离开页面时死亡的Cookie

问题描述:

Is it somehow possible (using Laravel5.2/PHP or/and JS/jQuery) to set cookie that expires when user leaves a certain page or certain domain?

是否有可能(使用Laravel5.2 / PHP或/和JS / jQuery)设置过期的cookie 用户离开某个页面或某个域? p> div>

window.onclose method can be called to delete cookies

Basically cookie is saved in client's machine. But if you want to delete cookie by closing window use a session ($_SESSION) cookie. It will automatically expire on window close.

In your case it will be better to use window.onclose and find the specific page by getting Laravel URL class and delete the cookie

You can set the cookies to expire when the session end (a.k.a when the user closes the browser), also you have the option to programatically delete the cookies inside Laravel, which if u want can also be triggered by making your own ajax call to your own controller.

You can find the expire on close option inside the config\session.php