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

Laravel cookie cannot be cleared, is it a BUG?

WBOY
Release: 2016-07-06 13:53:14
Original
1051 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template