使cookie在3或5秒后过期

时间:2015-09-25 11:28:55

标签: php

我的网站上需要一个cookie只需几秒钟。我试过的是这个:

$value = 12;
$cookie = setcookie("myCookie", $value, time() + 3);

Cookie已创建,但需要更长时间才能超过3秒

1 个答案:

答案 0 :(得分:0)

这里非常简单的数学时间。

$value = 12;

$seconds_in_seconds = 1;
$minute_in_seconds = 60
$hour_in_seconds = 60 * 60;
$day_in_seconds = 60 * 60 * 24
$week_in_seconds = 60 * 60 * 24 * 7
  /*ect...*/
/*60 seconds in a minute. Times 2 minutes plus 10 seconds. Makes 2 minutes and ten seconds.*/
$time = time() + (2 * $minute_in_seconds) + (10 * $seconds)
$cookie = setcookie("myCookie", $value, $time);