douxian6260 2015-09-25 11:28
浏览 192

使cookie在3或5秒后过期

I need a cookie on my site just for a few seconds. What i tried is this:

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

The cookie gets created, but needs longer to expire than 3 seconds

  • 写回答

1条回答 默认 最新

  • douchuifk90315 2015-09-25 12:17
    关注

    Very simple time math here.

    $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);
    
    评论

报告相同问题?