4

I want to set PHP COOKIE which should be stored for only one day. Setting a cookie for one day is easier.

If the user visits the site at 6PM, then the cookie should be set for another six hours only.

$tomorrow = mktime(0,0,0,$month,$date+1,$year);

where month, date and year are from the PHP date function. Will the above code work as i expected?

Or is there any better way to do this?

Boaz
  • 19,892
  • 8
  • 62
  • 70
Prabha Vathi
  • 347
  • 1
  • 4
  • 10
  • This would probably work (haven't tested), but keep in mind that this will use the server timezone, not the user's time. – Maxim Kumpan Sep 11 '13 at 11:23
  • @ÁlvaroG.Vicario OP is asking for beginning of next day, not the next 24 hours. – Boaz Sep 11 '13 at 12:19
  • @Boaz - You're right, I've misread that detail. It's a dupe of [How do I find the unix timestamp for the start of the next day in php?](http://stackoverflow.com/questions/2520404/how-do-i-find-the-unix-timestamp-for-the-start-of-the-next-day-in-php). – Álvaro González Sep 11 '13 at 12:36

1 Answers1

6

Try using the strtotime() function with the tomorrow keyword:

$tomorrow = strtotime('tomorrow');
Boaz
  • 19,892
  • 8
  • 62
  • 70