Home >Backend Development >PHP Tutorial >Laravel cookie cannot be cleared, is it a BUG?

Laravel cookie cannot be cleared, is it a BUG?

WBOY
WBOYOriginal
2016-07-06 13:53:141047browse

The cookie shown in the picture, I want to clear the ES_name cookie
Laravel cookie cannot be cleared, is it a BUG?

Set up a route

<code>Route::get('/admin/test', function(){
    response('')->withCookie(cookie('ES_name','',-1));
});</code>

Then the cookie is still there after accessing /admin/test
Laravel cookie cannot be cleared, is it a BUG?

Replace routing with

<code>Route::get('/admin/test', function(){
    setcookie('ES_name', '', -1, '/');
});</code>

It doesn’t work either. Using Cookie’s forget or make settings still doesn’t work. It can only be cleared by changing the address to a first-level route like /logout.
Is it a BUG in laravel, or did I not notice what needs to be set?

Reply content:

The cookie shown in the picture, I want to clear the ES_name cookie
Laravel cookie cannot be cleared, is it a BUG?

Set up a route

<code>Route::get('/admin/test', function(){
    response('')->withCookie(cookie('ES_name','',-1));
});</code>

Then the cookie is still there after visiting /admin/test
Laravel cookie cannot be cleared, is it a BUG?

Replace routing with

<code>Route::get('/admin/test', function(){
    setcookie('ES_name', '', -1, '/');
});</code>

It doesn’t work either. Using Cookie’s forget or make settings still doesn’t work. It can only be cleared by changing the address to a first-level route like /logout.
Is it a BUG in laravel, or did I not notice what needs to be set?

Thank you, I succeeded according to your method, I will study it again.

<code>$cookie = Cookie::forget('ES_name');
return Redirect::route('admin')->withCookie($cookie);</code>

This is because after setting the cookie, you need to redirect it to take effect, because the http response will operate the cookie change to take effect.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn