1

I'm using the following function to programmatically login users via the frontend:

function auto_login() {
    $username = $_POST['user'];
    if ( !is_user_logged_in() ) {
        $user = get_userdatabylogin( $username );
        $user_id = $user->ID;
        wp_set_current_user( $user_id, $user_login );
        wp_set_auth_cookie( $user_id );
        do_action( 'wp_login', $user_login );
    }     
}
add_action('wp_ajax_auto_login', 'auto_login');
add_action('wp_ajax_nopriv_auto_login', 'auto_login');

However one weird issue I've run into is the following scenario:

1. User 1 logs in on PC 1

2. User 1 email is displayed as logged in in PC 1

3. User 2 logs in on PC 2

4. User 1 email is displayed as logged in in PC 2

I think this might be due to conflicting sessions but I'm not sure. I've looked up on this for quite a few days on Google yet nothing really came up which helped me.

So my question is, how do I solve this issue of conflicting sessions?

Thanks

4
  • WordPress by default doesn't use session, it uses cookies
    – Amirmasoud
    Aug 16 '14 at 8:14
  • So what is the issue here, why does different computers and different IP's display the same user as logged in? Aug 16 '14 at 8:16
  • Do you have caching enabled? Varnish?
    – Tom J Nowell
    Aug 16 '14 at 8:34
  • I've got APC running on the server itself and Varnish running on a Load Balancer Aug 16 '14 at 8:35

Your Answer

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

Browse other questions tagged or ask your own question.