Reputation: 12138
I need to set a cookie in CodeIgniter that expires at midnight on the same day it was set. According to their cookie documentation, you set the expire time in seconds; you can't provide a specific date and time.
Is there any other way to set a cookie and provide a specific date and time, or do I really need to calculate the difference in seconds from now until midnight tonight?
Upvotes: 0
Views: 1425
Reputation: 102784
You have to calculate the time, which is the number of seconds until the cookie should expire. It's easier than you probably think:
$expire = strtotime('midnight') - time();
If you have the date helper loaded, replace time()
with now()
.
Upvotes: 1