wp_signon not loggin in user to WordPress

I'm using the below script to log the user in, but when I run an if statement for is_user_logged_in(), but it doesn't seem to return the user as logged in.

?php if( isset($_POST['username']) ){
    $username = $_POST['username'];
    $password = $_POST['password'];
    $remember = $_POST['remember'];

    $user = get_user_by( 'login', $username );
    $user_id = $user-ID;

    if( $remember == 'on' ){
        $remember_pass = true;
    } else {
        $remember_pass = false;
    }

    if ( $user  wp_check_password( $password, $user-data-user_pass, $user-ID) ){
        $credentials = array(
            'user_login' = $username,
            'user_password' = $password,
            'remember' = true,
        );
        $auth = wp_signon( $credentials, false );
        if ( is_wp_error($auth) ){
            $auth-get_error_message();
        } else {
            echo 'pSuccess./p';
        }
    } else {                    
        echo 'div class="result-box warning"Wrong username or password. Please try again./div';
    }
} ?

What exactly am I doing wrong here? Everything is posting correctly, and the array() is working fine. If I run a is_wp_error() with the $auth, I still get a success message. So it's login in, just not actually giving them a session?

Topic wp-signup wp-login-form login Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.