Title: Logging user in with PHP
Last modified: October 3, 2016

---

# Logging user in with PHP

 *  [f2099](https://wordpress.org/support/users/f2099/)
 * (@f2099)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/logging-user-in-with-php/)
 * 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( "http://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.

## Tags

 * [login](https://wordpress.org/support/topic-tag/login/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [f2099](https://wordpress.org/support/users/f2099/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/logging-user-in-with-php/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
