WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Logging in from external PHP script and staying logged in (4 posts)

  1. napoleon09
    Member
    Posted 3 years ago #

    My requirement is to login the user into WP from an external PHP script and publish a post.
    Once logged in, I would like the user to navigate to a regular wordpress page and not require to log in (manually) again.
    Everything including the posting is working fine,

      except
    when I open a new browser tab or navigate to a wordpress page from my PHP script the user is found not logged in.
    I am using the following function to log in the user. What am I missing?

    function _my_user_login($username,$password) {
      $creds = array();
      $creds['user_login'] = $username;
      $creds['user_password'] = $password;
      $creds['remember'] = true;
      $user = wp_signon( $creds, false );
      wp_set_current_user($user->ID);
      wp_set_auth_cookie($user->ID, true);
      return $user;
    }

    Thanks in advance.

  2. napoleon09
    Member
    Posted 3 years ago #

    One little update. I checked the cookies and I am seeing 3 cookies set for the user. Including the logged_in cookie, which expires 14 days from now. But still for some reason I am not getting logged in from another/same browser window.

    Thanks

  3. napoleon09
    Member
    Posted 3 years ago #

    It was a red-herring, please ignore it. The issue was that cookie URL set had a www while the page where I was trying to access it had the domain name without www, hence the browser was not sending the right headers in GET. My bad.

  4. roydellray@gmail.com
    Member
    Posted 3 years ago #

    I have developed several custom php pages & a css page on my local computer NOT using wordpress, these query a mysql db and subsequently display results. Now I need to integrate them into an existent site created by WordPress, where do I upload these files to and how do I link them to a wordpress php page, where do they live?.

Topic Closed

This topic has been closed to new replies.

About this Topic