CakePHP cookie在浏览器关闭后不会持续 [英] CakePHP cookies not persisting after browser close

查看:260
本文介绍了CakePHP cookie在浏览器关闭后不会持续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于资源消耗较低,我正在偏离Apache而偏向于nginx。我设置了一个安装了LEMP堆栈的Ubuntu服务器盒。在移动我的所有应用程序(3个CakePHP 2.0.5应用程序,1个Wordpress安装)后,一切似乎工作完美除了一件事 - Cake的cookies突然消失,当浏览器关闭时。



我创建了一个非常简单的测试PHP页面来测试,如果cookie是在所有工作,他们实际上是工作,只是不在蛋糕。



使用Chrome开发者工具,我已经检查过是否已经设置了cookie,并且如下所示:





过期日期甚至设置为一个月的未来,所以我不明白为什么他们不通过浏览器关闭。一旦我启动浏览器并导航到我的应用程序,该cookie现在走了:





我注意到的一件事是我的应用程序在Apache上运行, CAKEPHP 您在上面看到的cookie在关闭之前和之后具有相同的值。但是在nginx服务器上,每次我关闭并重新打开我的浏览器时,该cookie都有不同的值。



我认为这可能与会话有关,我的会话设置在 core.php ,它的设置让PHP做会话处理:

  Configure :: write('Session',array(
'defaults'=>'php'
));

我检查了我的 / tmp 目录和会话文件正在创建。我尝试将会话处理程序更改为 cake ,以便Cake将会话存储在其 app / tmp / sessions 目录中,



有任何人在nginx和Cake之间经历过这种行为,或者有任何想法


解决方案

问题与加密的Cookie和Suhosin补丁有关。显然suhosin忽略任何 mt_srand() srand()调用你做并初始化随机函数本身[ see here ]。因为Cake依赖这些功能,它干扰了我的加密cookie。要修复它,我添加这两行到我的php.ini文件,并重新启动服务器(注意,只是重新启动nginx不工作):

  suhosin.srand.ignore = Off 
suhosin.mt_srand.ignore = Off


I am in the process of moving away from Apache in favor of nginx due to the lower resource consumption. I have set up an Ubuntu Server box with the LEMP stack installed. After moving all my applications over (3 CakePHP 2.0.5 apps, 1 Wordpress install), everything seems to be working perfectly except for one thing - Cake's cookies suddenly disappear when the browser is closed.

I have created a very simple test PHP page to test if cookies are working at all and they are in fact working, just not in Cake. Wordpress is also not having any troubles remembering me when I close my browser.

Using the Chrome developer tools, I have inspected to see if the cookie is being set at all, and it is as you can see below:

The expiry date is even set a month into the future as well, so I don't understand why they don't live past browser close. As soon as I fire my browser up and navigate to my app, the cookie is now gone:

One thing I did notice is that with my app running on Apache, the CAKEPHP cookie you see above above has the same value before and after close. However on the nginx server, that cookie has a different value everytime I close and re-open my browser.

I thought this might have to do with sessions, so I checked my session settings in core.php and it's set to let PHP do the session handling:

Configure::write('Session', array(
    'defaults' => 'php'
));

I've checked my /tmp directory and session files are being created. I tried changing the session handler to cake so that Cake would store sessions in its app/tmp/sessions directory, and while the sessions would successfully get created in this directory my cookies are still lost on browser close.

Has anybody experienced this behavior between nginx and Cake before, or have any ideas as to why this might be happening?

解决方案

The problem is related to encrypted cookies and the Suhosin patch. Apparently Suhosin ignores any mt_srand() and srand() calls you make and initializes the randomizer itself [see here]. Because Cake relies on these functions, it was interfering with my encrypted cookies. To fix it, I added these two lines to my php.ini file and rebooted the server (note that simply restarting nginx didn't work):

suhosin.srand.ignore = Off
suhosin.mt_srand.ignore = Off

这篇关于CakePHP cookie在浏览器关闭后不会持续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆