I have a skript that allows just one concurrent wordpress-session by destroying all other actrive sessions of a user when this user is logging in to wordpress:

add_filter('authenticate', 'wpse_12282015_single_login_authenticate', 0, 3);

function wpse_12282015_single_login_authenticate($user, $username, $password) {

    $user =  get_user_by('login', $username);

    if( isset($user->ID) ){

        if(isset($user->roles) && is_array($user->roles)) {

            //check for admins
            if(in_array('administrator', $user->roles)) {

                // admin can log in more than once
                return $user;
            }
        }

        // get all sessions for user
        $sessions = WP_Session_Tokens::get_instance($user->ID);

        // destroy everything since we'll be logging in shortly
        $sessions->destroy_all();
    }

    return $user;
}

Now, I would like to add a function that automativcly redirects the destroyed sessions, if open, to another page.

For example, if an user is logged in via the Crome Browser and is logging at the same time in firefox, the page in Chrome should detect the destroyed session (for example through ajax-loops every 10 seconds) and redirects automaticly to a page.

How could I achieve this? Thank you for any hints or tipps.

Regards

Jens

Read more here: WordPress:Destroy session and redirect user instantly


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: