cakephp,会话不工作,除非在浏览器中允许cookie [英] cakephp, session not working unless allow a cookie in browser

查看:292
本文介绍了cakephp,会话不工作,除非在浏览器中允许cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最新版本的cakephp v2.3.3

Using latest version of cakephp v2.3.3

当浏览器不允许Cookie时,我的会话变数有问题。
我将变量从一个控制器传递到另一个,这工作完美,只要浏览器启用了Cookie。我已经尝试过与控制器中的会话助手,但没有努力,同样的问题。

I have a problem with my session variables when a browser doesn't allow cookies. I pass variables from one controller to the other and this works perfect as long as the browser has cookies enabled. I have tried it with the Session helper in the controllers, but no effort, same problem.

如何解决这个问题,是否有解决方案?

How to fix this, is there a work around???

推荐答案

Cookie需要跟踪会话ID,但您可以使用 $ this-> Session-> id()手动获取或设置会话ID。 。通过将下面的代码添加到App Controllers的过滤器之前,您可以将会话ID设置为一个URL参数,如 http://example.com/posts/view/1?session=qkv108c2pqeubcpeos1q7ekds3 ,例如

Cookies are required to keep track of the session ID, but you can manually get or set the session ID using $this->Session->id(). By adding the code below to the App Controllers' before filter you can set the session ID as a URL paramter like http://example.com/posts/view/1?session=qkv108c2pqeubcpeos1q7ekds3, for example.

if (!empty($this->request->query['session'])) {
    $this->Session->id($this->request->query['session']);
}

每个请求都需要会话ID,每个链接。我建议扩展HTML助手的网址和链接方法以自动添加。

The session ID is required for every request which means you have to include it in every link. I would suggest extending the HTML helpers' url and link methods to automatically add it.

编辑

您应该验证 $ this-> Session-> read('Config.userAgent'); $ this - > request-> clientIp(); 没有更改,因为用户已通过身份验证以防止会话劫持。感谢thaJeztah指出这一点。

You should verify that $this->Session->read('Config.userAgent'); or $this->request->clientIp(); has not changed since the user was authenticated to prevent session hijacking. Thanks to thaJeztah for pointing this out.

这篇关于cakephp,会话不工作,除非在浏览器中允许cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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