1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Login with PHP strange problem

Discussion in 'XenForo Development Discussions' started by Chris.E, Aug 8, 2016.

  1. Chris.E

    Chris.E Member

    Hi Guys,

    I have some code that I am using to log in users via my website using PHP. It seems to work, but the problem is that after hitting the code below, the first time they visit the forum it doesnt recognize them as logged in. If they refresh the page once more they are then logged in.

    The code I am running is part of the XENForoSDK:

    $userModel = XenForo_Model::create('XenForo_Model_User');
    // Set cookie if needed
    if($remember) {
    $userModel->setUserRememberCookie($user);
    }
    // Log IP
    XenForo_Model_Ip::log($user, 'user', $user, 'login');
    // delete current session
    $userModel->deleteSessionActivity(0, $_SERVER['REMOTE_ADDR']);
    $this->getSession()->changeUserId($user);
    $this->getVisitor()->setup($user);

    $user = $this->getUser();
    return $user;
     
  2. Chris.E

    Chris.E Member

    I have noticed that when i hit the forum for the first time i get a 404 error and the cookies look like they are http only... my site runs on https so maybe thats the problem....


    cache-control:private, max-age=0
    cf-ray:2cf0ae874a3717b6-SIN
    content-encoding:gzip
    content-type:text/html; charset=UTF-8
    date:Mon, 08 Aug 2016 05:48:52 GMT
    expires:Thu, 19 Nov 1981 08:52:00 GMT
    last-modified:Mon, 08 Aug 2016 05:48:52 GMT
    pragma:no-cache
    server:cloudflare-nginx
    set-cookie:xf_session=3f833bf93f8d47b81b5c564b5948a78f; path=/; domain=.xxx.com; secure; httponly
    set-cookie:xf_user=1%2C80101ba833c6fc5bdd04b735a8fd59c8ab1ab856; expires=Wed, 07-Sep-2016 05:48:52 GMT; Max-Age=2592000; path=/; domain=.xxx.com; secure; httponly
    set-cookie:xf_user=1%2C80101ba833c6fc5bdd04b735a8fd59c8ab1ab856; expires=Fri, 07-Oct-2016 05:48:52 GMT; Max-Age=5184000; path=/; domain=.xxx.com; secure; httponly
    set-cookie:xf_logged_in=1; expires=Wed, 07-Sep-2016 05:48:52 GMT; Max-Age=2592000; path=/; domain=.xxx.com; secure; httponly
    set-cookie:xf_logged_in=1; expires=Wed, 07-Sep-2016 05:48:52 GMT; Max-Age=2592000; path=/; domain=.xxx.com; secure; httponly
    set-cookie:xf_logged_in=1; expires=Wed, 07-Sep-2016 05:48:52 GMT; Max-Age=2592000; path=/; domain=.xxx.com; secure; httponly
    set-cookie:xf_user=1%2C80101ba833c6fc5bdd04b735a8fd59c8ab1ab856; expires=Wed, 07-Sep-2016 05:48:52 GMT; Max-Age=2592000; path=/; domain=.xxx.com; secure; httponly
    set-cookie:xf_user=1%2C80101ba833c6fc5bdd04b735a8fd59c8ab1ab856; expires=Fri, 07-Oct-2016 05:48:52 GMT; Max-Age=5184000; path=/; domain=.xxx.com; secure; httponly
    set-cookie:xf_logged_in=1; expires=Wed, 07-Sep-2016 05:48:52 GMT; Max-Age=2592000; path=/; domain=.xxx.com; secure; httponly
    status:404
    vary:Accept-Encoding
    x-frame-options:SAMEORIGIN
     
  3. Chris.E

    Chris.E Member

    Problem solved!

    It was a third party addon i installed that changed how the cookies behaved. RL_LoggedInCookie to be exact. I just had to reuse the cookie create set up they did in when my users log in and the problem was fixed.
     

Share This Page