2015-09-25 148 views
0

我需要在我的網站上一個cookie只需幾秒鐘。我的嘗試是這樣的:使Cookie在3或5秒後過期

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

的餅乾被創建,但需要3秒以上

+0

'expire'參數需要自epoch以來的秒數。相反,您正在向當前時間添加3000秒(50分鐘)。我認爲你的意思是這樣的:'setcookie(「myCookie」,$ value,time()+ 3);' – Henders

+0

@AndyHenderson那正是他編碼的? – RiggsFolly

+0

答案已經被編輯。它最初說'$ cookie = setcookie(「myCookie」,$ value,time()+(3 * 1000));' – Henders

回答

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);