CakePHP的Cookie越来越乱 - 相关的Suhosin [英] CakePHP Cookies getting scrambled - Suhosin related

查看:296
本文介绍了CakePHP的Cookie越来越乱 - 相关的Suhosin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,我无法在任何页面上的CakePHP应用程序中读取任何Cookie,因为它们已设置,返回的唯一的东西是乱码文本。



我的代码很简单:

  $ this-> Cookie-> write('Region','test '); 
$ reg = $ this-> Cookie-> read('Region');
pr($ reg);

我取消注释$ this-> Cookie-> write()行,束随机控制字符。我也最近升级到CakePHP 1.3,但AFAIK这不应该影响cookie这样...
这是工作正常,直到更改服务器,这必须是我的问题的根。 p>

更新
在进一步探讨之后,我发现这是一个已知的问题,用于PHP的Suhosin安全补丁影响rand() srand()方法,我已经配置了suhosin允许rand()函数,但仍然发生,是否有更有效的工作周围。

解决方案

尝试此代码将禁用Cookie加密:

  $ this-> Cookie-> ('Region','test',false); 
$ reg = $ this-> Cookie-> read('Region');
pr($ reg);

写入方法具有以下参数:



write(mixed $ key,mixed $ value,boolean $ encrypt,mixed $ expires)



cookie中的所有值都由CakePHP加密。但是出于安全考虑,您可能希望考虑使用加密。


For some reason I am unable to read any cookies from my CakePHP app on any page after they have been set, the only thing that is returned is garbled text.

My code is as simple as this:

$this->Cookie->write('Region', 'test');
$reg = $this->Cookie->read('Region');
pr($reg);

I uncomment the $this->Cookie->write() line and all I get back is a bunch of random control characters. I also recently upgraded to CakePHP 1.3 but AFAIK this should not effect cookie like this... This was working fine until I changed server, this must be the root of my problem.

Update After probing around further I have discovered this is a known issue with the Suhosin security patch for PHP effecting the rand() and srand() methods, I had configured Suhosin to allow the rand() functions but still it is happening, is there a more effective work around out there?

解决方案

Try this code which will disable cookie encryption:

$this->Cookie->write('Region', 'test', false);
$reg = $this->Cookie->read('Region');
pr($reg);

The write method has the following params:

write(mixed $key, mixed $value, boolean $encrypt, mixed $expires)

By default all values in the cookie are encrypted by CakePHP. However for security reasons you may wish to look into working with the encryption.

这篇关于CakePHP的Cookie越来越乱 - 相关的Suhosin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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