2012-05-24 21 views
1

我想在symfony2項目中設置一個cookie。 一切工作正常,只是在瀏覽器關閉後cookie被刪除。我試圖設置到期時間,但它會拋出一個錯誤:Expiry date cannot have a year greater then 9999Cookie過期不適用於Symonfy 2

我該如何解決它?

這裏是我的代碼:

$time = time() * 3600 * 24 * 7; 
$response = new Response(); 
$response->headers->setCookie(new Cookie('lang', $lang, $time)); 
$response->send(); 

回答

9

$time計算應

$time = time() + (3600 * 24 * 7); 
+0

這也幫助了我。 – King