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.
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()?
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.
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.