简体   繁体   English

注销后禁用后退按钮?

[英]Disable back button after logout?

I am using php.我正在使用 php。 i want redirect users to logout page when he clicks back button after login.我想在用户登录后单击后退按钮时将用户重定向到注销页面。 How to achieve this?如何实现这一目标? where to write the code?在哪里写代码?

i logged into site admin..logged out and then hit back button and i am able to see the previous page.我登录到站点管理员..注销然后回击按钮,我能够看到上一页。 Why site admin does not handle this.为什么站点管理员不处理这个。

This is the code for logout in site admin:这是站点管理员中注销的代码:

if( !function_exists( 'adifier_logout_inactive' ) ){
function adifier_logout_inactive( $username, $user ){
    if( !is_wp_error( $user ) ){
        $logout = true;
        if( !empty( $user->allcaps['edit_posts'] ) && $user->allcaps['edit_posts'] === true ){
            $logout = false;
        }
        else if( get_user_meta( $user->ID, 'user_active_status', true ) == 'active' ){
            $logout = false;
        }
        if( $logout === true  ){
            wp_logout();
        }
    }
}
add_filter( 'wp_login', 'adifier_logout_inactive', 10, 2 );
}

First question: What is the back button ?第一个问题:什么是back button

Answer: It is a button outside the control of the web server.答:它是一个不受 Web 服务器控制的按钮。 If presses, the browser loads again the page with the previous used URL.如果按下,浏览器将再次加载具有先前使用过的 URL 的页面。 Some browsers (or all?) support a back N steps button .某些浏览器(或全部?)支持back N steps button

What does the web server see? Web 服务器看到什么?

The web server sees only the URL. Web 服务器只能看到 URL。 He does't know if the URL is loaded again or if the user used one of the back buttons.他不知道 URL 是否再次加载,或者用户是否使用了后退按钮之一。 So the (new) URL is the only data for the decision.所以(新的)URL 是决定的唯一数据。 The only chance to recognize the the usage of a back button is to use session data too.识别back button用法的唯一机会也是使用会话数据。

Pitfalls: The user can open several windows.陷阱:用户可以打开多个窗口。 He can press the reload button.他可以按下重新加载按钮。 He can set and use bookmarks.他可以设置和使用书签。

With this knowledge you should rethink how to detect thew back button and if you really want to mange (some aspects of) it.有了这些知识,您应该重新考虑如何检测back button以及您是否真的想管理它(的某些方面)。 Or in other words: Is it rally worth to forbid loading the previous URL again.或者换句话说:禁止再次加载以前的 URL 是否值得。

A soluton may be: If the user enters the login page and is already logged-in, then redirect him to another page (welcome, status, overview).一个解决方案可能是:如果用户进入登录页面并且已经登录,则将他重定向到另一个页面(欢迎、状态、概览)。 I do that at my websites.我在我的网站上这样做。

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

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