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

Problem with $lifetime in setCookie() function

Discussion in 'XenForo Development Discussions' started by @Meigem, Jan 29, 2014.

  1. @Meigem

    @Meigem New Member

    I'm creating an external login form in my website and I have a problem with the parameter $lifetime in setCookie() function (from XenForo_Helper_Cookie).

    This is the setCookie() function in XenForo_Helper_Cookie:

    PHP:
    public static function setCookie($name$value$lifetime 0$httpOnly false$secure null)
    {
        
    $expiration = ($lifetime ? (XenForo_Application::$time $lifetime) : 0);
        return 
    self::_setCookieInternal($name$value$expiration$httpOnly$secure);
    }
    My login form works perfectly if the checkbox for keep connected is checked, but if the checkbox isn't checked, doesn't work as I want. If isn't checked, the login works but the $lifetime isn't 0.

    This is my code:

    PHP:
    // In setCookie() I put 0, but apparently doesn't work.
    if ($bRemember) {
        
    $dbUserModel->setUserRememberCookie($iUserID);
    }
    else {
        
    $value $dbUserModel->getUserRememberKeyForCookie($iUserID);
        if (!
    $value)
        {
            return 
    false;
        }
       
        
    XenForo_Helper_Cookie::setCookie('user'$value0);
    }
     
  2. AndyB

    AndyB Well-Known Member

  3. Chris D

    Chris D XenForo Developer Staff Member

    What is the resulting cookie lifetime with your code?
     
  4. AndyB

    AndyB Well-Known Member

    The default cookie lifetime is 30 days. My add-on does not change this setting.
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    I was talking to the guy who is asking for help with his code.
     
  6. cclaerhout

    cclaerhout Well-Known Member

    I think the question to check is when do you execute your code? XenForo probably overrides your settings by it's own internal functions when the session is created. In other words, it probably uses the same helper for the same cookie value but after you. To check this, just dump a fake variable in your code (ie:1) and in the method "setUserRememberCookie" from the class "XenForo_Model_User" (ie:2).
     
  7. @Meigem

    @Meigem New Member

    This is not what I want. What I want is that if the checkbox is pressed, the lifetime is 0 seconds for the session to close automatically.

    The resulting cookie is the same, press or not press the checkbox.
     

Share This Page