Part of the EllisLab Network
   
 
Cookie Helper default expire time
Posted: 04 May 2008 11:53 PM   [ Ignore ]  
Summer Student
Total Posts:  7
Joined  01-28-2008

in cookie_helper.php

if ( ! is_numeric($expire))
{
    $expire
= time() - 86500;
}
else
{
    
if ($expire > 0)
    
{
        $expire
= time() + $expire;
    
}
    
else
    
{
        $expire
= 0;
    
}
}

if parameter $expire is not passed by the function set_cookie, it has a default value ‘’, and the $expire will set to time() - 86500, which has no effect to set the cookie, you should change it to

if ( ! is_numeric($expire))
{
    $expire
= time() + 86500;
}
else
{
    
if ($expire > 0)
    
{
        $expire
= time() + $expire;
    
}
    
else
    
{
        $expire
= 0;
    
}
}

Profile
 
 
Posted: 05 May 2008 06:10 AM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1089
Joined  01-07-2008

It’s correct the way it is.  From the docs:

The expiration is set in seconds, which will be added to the current time. Do not include the time, but rather only the number of seconds from now that you wish the cookie to be valid. If the expiration is set to zero the cookie will only last as long as the browser is open.

To delete a cookie set it with the expiration blank.

The negative time will mean the cookie expires immediately, thus deleting it.

 Signature 

Blog | Twitter | Coffee

Profile
 
 
Posted: 05 May 2008 06:36 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  7
Joined  01-28-2008
inparo - 05 May 2008 06:10 AM

It’s correct the way it is.  From the docs:


The expiration is set in seconds, which will be added to the current time. Do not include the time, but rather only the number of seconds from now that you wish the cookie to be valid. If the expiration is set to zero the cookie will only last as long as the browser is open.

To delete a cookie set it with the expiration blank.

The negative time will mean the cookie expires immediately, thus deleting it.

YES, what you said is the parameter passed to the set_cookie() function, and what I talked is the default $expire value used in the set_cookie() function and pass it to the native setcookie() function.  If you don’t invoke the $expire parameter, the CI will automatically use $expire - 86500 as the expire time, and pass it to the native setcookie() function, which means that the cookie will expire in the past time. Do you think this is right?

in PHP docs,

The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you’ll most likely set this with the time() function plus the number of seconds before you want it to expire.

Profile
 
 
Posted: 05 May 2008 05:12 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1089
Joined  01-07-2008

I think you’re missing what the default is for.  It’s only used to delete the cookie.

By telling the browser that the cookie has expired, it will be trashed on the next request.

 Signature 

Blog | Twitter | Coffee

Profile
 
 
Posted: 05 May 2008 08:14 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  7
Joined  01-28-2008
inparo - 05 May 2008 05:12 PM

I think you’re missing what the default is for.  It’s only used to delete the cookie.

By telling the browser that the cookie has expired, it will be trashed on the next request.

i don’t think so.
the ci docs said that:
Only the name and value are required.
so if i just pass the name and value, the cookie will be deleted, isn’t it?

for example:
set_cookie(’name’, $value);

what happened after i call this?? the cookie will be deleted!! this is not what i want

Profile
 
 
Posted: 05 May 2008 08:35 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  7
Joined  01-28-2008

To delete a cookie set it with the expiration blank.

I think it’s my fault~~nice discussion with inparo

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 61065 Total Logged-in Users: 22
Total Topics: 73887 Total Anonymous Users: 1
Total Replies: 398535 Total Guests: 338
Total Posts: 472422    
Members ( View Memberlist )