1

I am trying to find a solution for 2 months now but unfortunately I came up with no results. I have a subscription based website which streams music. What customers basically buy is a "panel" where they are listening to music without the need to refresh the page. What I need is to disallow their account being logged in if it is already in use. I found many plugins that force the user to log out but this happens only if they refresh the page. It could also work if for example: A logs in. B logs in with the same account and at this time A is being automatically logged out (I guess with the use of Ajax). It's a bit weird that nobody needed this in the past. Anyone could help?

Thanks in advance.

  • Mostly what I tried is to make the "panel" page reload with ajax (no refresh) so plugins I found take effect but had no luck. – ArgGeo May 25 '14 at 20:05
  • How does your "panel page" work, exactly? – s_ha_dum May 25 '14 at 20:13
  • It has several stream channels and the client plays whatever he likes. – ArgGeo May 25 '14 at 20:22
  • That tells me what it does. It does not tell me how it works. – s_ha_dum May 25 '14 at 21:09
  • It does nothing except containing the stream channels (players). – ArgGeo May 25 '14 at 21:13
0

The reason you're not finding anything is because WordPress does not use any form of "sessions". Login status information is not saved, or retrieved.

Logging into WordPress basically sets a cookie in your browser which is a single authentication point. It is the equivalent of a username and password, with encryption and a timeout, all in one cookie. Well, two cookies.

Regardless, WordPress is stateless. If you want to log somebody out when they switch to another location, you need code above and beyond anything WordPress core itself. Which probably means custom code for your use case.

So, define your case in great detail, and maybe somebody can help you devise a solution. Best scenario.

0

This code worked for me in WordPress:

add_filter( 'authenticate','one_session_per_user', 30, 3 );

function one_session_per_user( $user, $username, $password ) {
    $sessions = WP_Session_Tokens::get_instance( $user->ID );
    $all_sessions = $sessions->get_all();
    if ( count($all_sessions) ) {
        $login_page  = home_url( '/mt-pages/login/already_login/' );
        wp_redirect( $login_page . "?login=false/already_login/" );
        exit;
    }
    return $user;
}
  • 1
    Answers should be more than a code snippet. Please file an edit and explain why this would work. Also, to properly format code in your answer (or question), highlight it and click {} above the edit box. – Gabriel Apr 26 '15 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.