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

 

posted @ 2017-12-03 19:42  与f  阅读(7013)  评论(1编辑  收藏  举报