• Resolved napoleon09

    (@napoleon09)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter napoleon09

    (@napoleon09)

    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

    Thread Starter napoleon09

    (@napoleon09)

    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.

    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?.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Logging in from external PHP script and staying logged in’ is closed to new replies.