如何设置 CakePhp 的会话变量以与 Chrome 一起使用?
我正在使用 CakePhp 开发一个网站。当上传到服务器并使用 Firefox 进行测试时,一切正常。
使用 Google Chrome 时,似乎没有创建会话变量。
如果我尝试访问主页,我会首先重定向到登录页面。登录后,它不会将我重定向到主页,而是再次重定向到登录页面。
我注意到会话变量不是用 Chrome 创建的,但在 Firefox 中工作得很好。
I am working on a website using CakePhp. When uploading to the server and testing with Firefox everything works great.
When using Google Chrome, it seems like no session variables are created.
If I try to access the home page, I'm redirected to the login page first. After I login it doesn't redirect me to the home page, but to the login page again.
What I noticed is that the session variables are not created with Chrome but works fine with Firefox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看此页面
这是链接。
既然使用浏览器时应该改变服务器行为?好吧,我不太清楚 Chrome 对引用站点做了什么,但似乎它正在以某些方式改变它。
而且cakePHP强制将session.referer_check设置为true,从而检查具有相同PHPSESSID的多个请求是否来自同一个url。
正如 php.net 上的一篇文章所言:
这两种设置结合起来,你就陷入了混乱。我首先找到了一个快速修复方法,即在 app/webroot/index.php 中强制设置 session_start() 。但经过更多的阅读和调试,我终于找到了罪魁祸首。
破解修复方法
没有简单的方法可以阻止 cake 设置此设置,但您可以在 Session.save 配置键中定义自己的会话处理程序。
只需在 app/config/ 中创建名为 session_custom.php 的文件并设置Configure::write('Session.save', 'session_custom');在你的 core.php 文件中。
在该文件中,只需删除以下行(从 cake_session.php 复制/粘贴)
Check this page
Here's the link.
Since when using a browser should change the server behavior ? Well I don't exactly know what Chrome is doing with the referer but it seems that it is altering it in some ways.
And cakePHP forces the setting of session.referer_check to true, thus checking that multiple requests with the same PHPSESSID comes from the same url.
As one posted on php.net :
Those two settings combined, and you got a hell of a mess. I first found a quick fix by forcing the setting of session_start() in app/webroot/index.php. But after more reading and debugging I finally found the culprit.
Hacking your way through the fix
There is no easy way to prevent cake from setting this setting, but you can define your own session handler in the Session.save configure key.
Just create file named session_custom.php in app/config/ and set Configure::write('Session.save', 'session_custom'); in your core.php file.
And in that file, just drop the following lines (copy/paste from cake_session.php)
如果我是对的,那么您正在尝试通过从 url 检索获取值来设置会话
如果是这样,我建议你使用经典的 php 风格的 url,例如
http://localhost/something/projects/view?id=4f0998ad -0538-4454-b51a-0ca46f441e7f
并使用
$_GET['id'] 在你的控制器中检索值
我可以说,因为我前段时间遇到了同样的麻烦,并搜索了大量博客以获取合适的解决方案,但没有找到任何地方,但使用上述方法解决了我的问题
If i am right then you are trying to set the session by retrieving the get value from the url
if so the i suggest you use the classic php style url like
http://localhost/something/projects/view?id=4f0998ad-0538-4454-b51a-0ca46f441e7f
and use
$_GET['id'] in your controller to retrieve the value
I can say because i was facing the same trouble some time ago and searched through lots of blog to get an appropriate solution but got no where but using the above approach solved my p
在您的
app/Config/core.php
中检查“cookie”中是否有空格,即使是下划线也可能会导致问题。
前段时间遇到了这个问题,我花了一段时间才弄清楚......
In your
app/Config/core.php
check 'cookie' has no whitespaces in it, even underlines may cause a problem.
Had this problem some time ago and it took me a while to figure it out...