We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Cookie Expire

Development and Programming

Simon Job's avatar
Simon Job
123 posts
15 years ago
Simon Job's avatar Simon Job

I’m trying to update an extension I made for EE 1.x that sets a cookie containing the user’s username for use with the Mint Pepper Secret Crush. (The old extension is here).

It seems, through using Live HTTP Headers Add-on with Firefox, that the cookie is being set with a date one year in the past.

This is the function in my extension, what am I doing wrong?

function set_mint_cookie()
{

    $cookie_value = $this->EE->session->userdata['username'];
    $cookie_name = $this->settings['cookie_name'];
    $expire = (60*60*24*365);
    $this->EE->functions->set_cookie($cookie_name,$cookie_value,$expire);
    
}

Thanks, Simon.

       
Simon Job's avatar
Simon Job
123 posts
15 years ago
Simon Job's avatar Simon Job

I’m bumping this, cause I still require assistance…

Help appreciated 😊

       
Chuck Liddell's avatar
Chuck Liddell
57 posts
15 years ago
Chuck Liddell's avatar Chuck Liddell

The code in EE that handles cookie expiration in set_cookie() looks like this:

if ( ! is_numeric($expire))
        {
            $expire = time() - 86500;
        }
        else
        {
            if ($expire > 0)
            {
                $expire = time() + $expire;
            }
            else
            {
                $expire = 0;
            }
        }
    
        setcookie($prefix.$name, $value, $expire, $path, $domain, 0);

From what I can see it looks like you’re setting the $expire value correctly.

Your server time isn’t mis-configured, is it? What is the output of time()?

       
Simon Job's avatar
Simon Job
123 posts
15 years ago
Simon Job's avatar Simon Job

Chuck,

Thanks for helping me out.

time() gives the current Epoch time correctly, when I tested: 1287860499.

The extension is attached if you were able to test. All it is supposed to do is set a cookie, by default exp_mint_nametag, with the current user’s username as it’s value.

Thanks, Simon.

       
Simon Job's avatar
Simon Job
123 posts
15 years ago
Simon Job's avatar Simon Job

Solved the problem.

This was wrong:

$cookie_value = $this->EE->session->userdata['username'];

will not work with the sessions_end hook, see:

http://ellislab.com/forums/viewthread/168569/

Extension now available: Mint Nametag

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.