简体   繁体   English

在Wordpress中关闭浏览器时清除用户会话

[英]Clear user session on closing browser in Wordpress

I want to clear the current session of a user on frontend in wordpress while closing the browser or tab. 我想在关闭浏览器或标签的同时清除wordpress中前端用户的当前会话。 Currently when I login and close the browser, the user is already logged in. 当前,当我登录并关闭浏览器时,该用户已经登录。

I am using Wordpress 4.0 version. 我正在使用Wordpress 4.0版本。 So please advise how I achieve this. 因此,请告知我如何实现这一目标。

If you can include a JavaScript and know the exact wordpress cookie you can use following code to detect on close event and inside clear the cookie 如果您可以包含JavaScript并知道确切的wordpress cookie,则可以使用以下代码检测close事件并在内部清除cookie

window.onbeforeunload = function () {
       // Clear cookie here
      };

Why don't you use the wp_logout function? 为什么不使用wp_logout函数? Destroys the active session. 销毁活动会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM