简体   繁体   English

Set-Cookie存在于标头响应中,但在浏览器中缺失

[英]Set-Cookie present in header response but missing in browser

Basically Session is not working. 基本上会话无法正常工作。 Session is getting generated and getting stored in the proper folder of the server, but not getting stored in the browser as the usual PHPSESSID cookie . 会话正在生成并存储在服务器的正确文件夹中,但没有像通常的PHPSESSID cookie那样存储在浏览器中。 The phpinfo() shows that the Set-Cookie headers are being sent, but Set-Cookie headers are missing in the response that the browser gets. phpinfo()表明正在发送Set-Cookie标头,但浏览器得到的响应中缺少Set-Cookie标头。 Please check the below screenshots: 请检查以下屏幕截图:

Set-Cookie headers present from the server side: 服务器端提供的Set-Cookie标头:

phpinfo屏幕快照,显示Set-Cookie标头

Set-Cookie headers missing in the response the browser gets: 浏览器得到的响应中缺少Set-Cookie标头:

浏览器屏幕截图显示未响应Set-Cookie

Another info is, if I use javascript to set cookie then it works and shows up in the browser's developer tool. 另一个信息是,如果我使用JavaScript设置cookie,则它可以工作并显示在浏览器的开发人员工具中。

Everything regarding session is ok, just that the cookie it tries to set on the browser seems to be not setting. 关于会话的一切都可以,只是试图在浏览器上设置的cookie似乎没有设置。

Answering the cause and fix as it may help someone in future and save many hours: 回答原因并解决,因为它可能会在将来对某人有所帮助并节省许多时间:

This error happened in a site previously built by someone else. 此错误发生在以前由其他人构建的站点中。 This error seemed quite unusual and I thought the problem is most probably with Apache. 该错误似乎非常罕见,我认为问题很可能与Apache有关。 I removed Apache and reinstalled to no effect. 我删除了Apache并重新安装没有任何效果。 Then I installed Nginx to see if the problem is with the Web Server software or the Server itself. 然后,我安装了Nginx,以查看问题是否出在Web服务器软件或服务器本身上。 And I found that Session is working fine in Nginx. 我发现Session在Nginx中工作正常。 So the problem was definitely with Apache somewhere. 因此,问题肯定出在某个地方的Apache。

As I checked the files found that in the .htaccess file somewhere down below Cookie was unset !! 当我检查文件时,发现在Cookie下方某处的.htaccess文件中未设置

Header unset Cookie
Header unset Set-Cookie

Never thought someone would have put that! 没想到有人会放那个! But anyway, removing the above fixed the problem. 但是无论如何,删除上面的内容可以解决问题。

Encountered the same behavior with a service provider of mine. 与我的服务提供商遇到了相同的行为。 Turned out to be a caching problem on their side (varnish cache). 事实证明,这是它们方面的缓存问题(清漆缓存)。

Luckily I was able to disable Varnish-Cache via the provided admin-backend. 幸运的是,我能够通过提供的admin-backend 禁用Varnish-Cache After that, the Set-Cookie headers were present in the client response. 之后,Set-Cookie标头出现在客户端响应中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM