title: Wordpress login via script
body: <p>I have tried to put together a php page that will log a user in/or create them and log them in. My user is getting created but when i try to go to a page WP just re-directs me to the actual login page. Below is the part that i cant get to work.</p>
  
  <pre><code>if ( !username_exists( $user_login_name ) ) {
      $user_id = wp_create_user( $user_login_name, md5($user_login_name), "" );
      $creds = array();
      $creds['user_login'] = $user_login_name;
      $creds['user_password'] = md5($user_login_name);
      $user = wp_signon( $creds, false );
      wp_set_current_user($user_id);
      if ( is_wp_error($user) )   {
          echo $user-&gt;get_error_message();
      }
      wp_set_auth_cookie( $user_id );
  } else  {
      $user = get_user_by('login', $user_login_name);
      $user_id = $user-&gt;ID;
      $creds = array();
      $creds['user_login'] = $user_login_name;
      $creds['user_password'] = md5($user_login_name);
      $user = wp_signon( $creds, false );
      wp_set_current_user($user_id);
      if ( is_wp_error($user) ){
          echo $user-&gt;get_error_message();            
      }
      wp_set_auth_cookie( $user_id );
  </code></pre>
  
  <p>}  </p>
  
  <p>Can anyone tell me what im doing wrong? Ive set the cookie, the current user, etc. But Still a no go.</p>