Yii Framework Forum: Cookie fails to save - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cookie fails to save if 'expire' property is set Rate Topic: -----

#1 User is offline   Spear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 09

Posted 08 April 2010 - 11:24 AM

I hate to ask dumb questions, but i can't to figure this one by myself :blink:

The thing is - application won't store a cookie if it has an 'expire' property set.

The code i'm workin' on is quite simple and yet - not working. Is it some kind of Yii bug?

$cName = '1_2vf';
$valueSet = 'test';
$cookieSet=new CHttpCookie($cName,$valueSet);

$a=intval($this->determineCookieLifetime()); // returns valid future timestamp, but anyway - "$a=time();" doesn't work either
		
$cookieSet->expire = $a;
Yii::app()->request->cookies[$cName]=$cookieSet;
exit;


That piece of code won't send any cookies to client browser, but it it works just fine if no 'expire' property is set - but this is not something i can bear with because cookie will be gone as soon as browser session is closed.

Help me, please!
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,336
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 April 2010 - 03:26 AM

What is the code of determineCookieLifetime()...

Fot the cookie duration you should use time() + time duration

for example 1 day is time() + 86400 (24 hours * 60 minutes * 60 seconds)
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   Spear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 09

Posted 09 April 2010 - 04:38 AM

Thank you! It actually was that i forgot to add time() to my timestamp calculations. Well, it's always a bad idea to code for 6-7 hours straight :) Thanks! B)
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,336
  • Joined: 12-October 09
  • Location:Croatia

Posted 09 April 2010 - 04:41 AM

You're welcome!
Find more about me.... btw. Do you know your WAN IP?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users