laravel的cookie操作


前提你的整個http流程一定要走完,頁就是必須走到view()或Response,你寫到中間中斷調試,cookie是設置不上去的......(坑~~)

讀取:

$value = Cookie::get('name');

寫入:

$cookie = Cookie::make('name', 'value', $minutes);//無return 好像有問題


return View::make(xxx)->withCookie($cookie);

刪除:

Cookie::forget('name');

 

另一種賦值刪除:

Cookie::queue('test', 'testValue', 10); // 10 分鍾

Cookie::queue('test', null , -1); // 銷毀

 

 

原生態的cookie操作

setcookie($name, $value , $_t, '/', $domain);

setcookie("user", "Alex Porter", time()+3600,'/','test.com');

打印:

var_dump($_COOKIE) ;

刪除:

php中使用“setcookie($cookiename, '');”或者“setcookie($cookiename, NULL);”都會刪除cookie

另一個辦法是設置Cookie的失效時間為 time()或time()-1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM