强制用户在4小时后重新登录-方式?

时间:2013-02-09 作者:J. Chin

有人知道有什么方法可以强制登录用户在4小时后重新登录吗?还是在今天的特定时间?

例如,如果他们在上午9点登录,我们可以强制他们在下午1点重新登录吗?

4 个回复
SO网友:Mark Kaplun

最简单的方法是更改身份验证cookie到期时间。

add_filter(\'auth_cookie_expiration\', \'wase_85171_expiry\',10,3);

function wase_85171_expiry($expiry, $user_id, $remember) {
  return 14400; // or calculate the time remaining till the time you want it to expire
}
人们可以在浏览器中延长cookie的有效期,但我相信没有人会介意

SO网友:Max Yudin

您可以编写javascript,它将从wp_login 操作,计数4x60x60 秒并将用户重定向到生成的URLwp_logout_url().

Update: 最好在用户空闲N分钟后才强制注销。您可以在中获得想法并链接到源代码jQuery idleTimer plugin 保罗·爱尔兰的文章。不幸的是,演示不起作用。

SO网友:tobbr

您可以通过调用wp\\u logout()函数以编程方式在Wordpress中注销用户。要将此应用于4小时规则,请考虑以下代码:

function user_update_login($login) {
    // function fires when a user logs in

    global $user_ID;
    $user = get_userdatabylogin($login);

    // save the current time when the user logged in
    update_usermeta( $user->ID, \'last_login\', time() );
}
add_action(\'wp_login\',\'user_update_login\');

function check_time_limit() {
    // populate the user objects
    get_currentuserinfo();
    global $user_ID;

    // only run if the user is logged in
    if($user_ID) {
        // get the last login time
        $last_login = get_user_meta($user_ID, \'last_login\', TRUE);

        // if the current time is greater than the last login
        // + 14400 seconds (4 hours) the user will be logged out
        if(time() > ($last_login + 14400)) {
            wp_logout();
        }
    }
}
check_time_limit();
将此代码放入函数中。php文件将在4小时后注销所有用户。如果只想将此规则应用于特定页面等,还可以将check\\u time\\u limit()的调用移动到主题中的任何位置。

SO网友:Md. Amanur Rahman

您只需使用名为WP Login Timeout Settings. 您可以设置loggedin用户重新登录的超时。

结束

相关推荐

修改wp-login.php标签:用户名为电子邮件

如何编辑wp-login.php 类型我使用电子邮件登录,所以我需要更改username 到email.这里的答案似乎过时了,或者与SSL或其他东西不兼容:Function to change a label (Username) in a core WordPress File (wp-includes/general-template.php) 我在函数文件中尝试了此操作,但没有成功:function wpse60605_change_username_label( $defaults ) {