• Hi, everyone. I’ve been doing some research on how to log a user in using PHP. Here’s what I have:

    if ( isset( $_POST[ "nome_de_usuario_ou_email" ] ) && isset( $_POST[ "senha" ] ) )
    {
        if ( username_exists( $_POST[ "nome_de_usuario_ou_email" ] ) || email_exists( $_POST[ "nome_de_usuario_ou_email" ] ) )
        {
            $credentials = array(
                'user_login'    => $_POST[ "nome_de_usuario_ou_email" ],
                'user_password' => $_POST[ "senha" ],
                'remember'      => true
            );
    
            $check = wp_authenticate_username_password( NULL, $_POST[ "nome_de_usuario_ou_email" ], $_POST[ "senha" ] );
    
            if ( is_wp_error( $check ) )
            {
                echo "<p>As credenciais fornecidas n&atilde;o est&atilde;o cadastradas.</p>";
            }
            else
            {
                $user = wp_signon( $credentials, false );
    
                wp_set_auth_cookie( $user->ID );
    
                /* Displays pricing table: */
                wp_redirect( "https://sellerconnect.com.br/index.php/precos/" );
            }
        }
        else
        {
            echo "<p>As credenciais fornecidas n&atilde;o est&atilde;o cadastradas.</p>";
        }
    }

    This isn’t working, though. I’m kind of confused on which functions to use. For example, should I use wp_set_current_user instead?

    Thanks in advance!

  • The topic ‘Logging user in with PHP’ is closed to new replies.