如果 cookie 设置为同一域上的所有子域,则删​​除 cookie 不起作用

Posted

技术标签:

【中文标题】如果 cookie 设置为同一域上的所有子域,则删​​除 cookie 不起作用【英文标题】:Delete cookie not working if cookie is set to all subdomains on same domain 【发布时间】:2017-07-30 14:42:03 【问题描述】:

我正在创建这样的 cookie:

Cookie::queue(Cookie::make('cookie_name', 'cookie_value', 60, '/', '.domain.com'));

据我了解,cookie 设置为全局域,我的意思是,此 cookie 也适用于子域。例如:example.domain.com

但是,如果我在子域上启动删除,我无法删除它。

Cookie::queue(Cookie::forget('cookie_name'));

我该怎么做?

感谢您的任何回答。

【问题讨论】:

【参考方案1】:

试试这个:

Cookie::queue('cookie_name', null, -1);
return Redirect::route('your_route');

【讨论】:

但这一个有效:Cookie::queue(Cookie::make('cookie_name', NULL, -999999, '/', '.domain.com')); 确认Cookie::queue(Cookie::make('cookie_name', NULL, -999999, '/', '.domain.com')); 是修复。非常感谢!【参考方案2】:

您可以使用此代码删除 cookie

$cookie = Cookie::forget('cookie_name', null, '.domain.com');
return response()->json(['success' => true, 'message' => 'You are successfully logged out.'])->withCookie($cookie);

【讨论】:

以上是关于如果 cookie 设置为同一域上的所有子域,则删​​除 cookie 不起作用的主要内容,如果未能解决你的问题,请参考以下文章