gpt4 book ai didi

php - CakePHP 2.6,Redis session /缓存在重定向时被销毁

转载 作者:IT王子 更新时间:2023-10-29 06:07:46 26 4
gpt4 key购买 nike

我正在将我们的项目从 Centos-6/Apache 2.0/PHP5.3/Cake 2.0/File Cache (6/3/2/0/F) 升级到 Centos-7/Apache 2.4/PHP5 .6/Cake 2.6/Redis 缓存和 session (7/6/4/6/R)。

如果我将 7/6/4/6/R 保留为文件缓存和 php session ,升级效果很好并且符合预期。但是我已经按照一些教程安装了 Redis,从 PHP 5.6 开始,一切都按预期工作,识别 Redis,CakePHP 在 test.php 中通过了 18 次测试,获得了 18 分,但是 Redis session 在重定向上被破坏了。

Core.php

//Replaces standard
Configure::write('Session', array(
'defaults' => 'cache',
'timeout' => '100',
'start' => true,
'checkAgent' => false,
'handler' => array(
'config' => 'session'
)
));
//Engine
$engine = 'Redis';

//Bottom of Core
Cache::config ('session', array (
'Engine' => $engine,
'Prefix' => $prefix . 'cake_session_',
'Duration' => $duration
));

Bootstrap.php

Cache::config('default', array('engine' => 'Redis'));

AppController.php

public $components = array(
'Session',
'Auth' => array(
'loginRedirect'=>array('controller' => 'companies', 'action' => 'view'),
'logoutRedirect'=>array('controller' => 'users', 'action' => 'login'),
'loginAction'=>array('controller' => 'users', 'action' => 'login'),
'authenticate' => array(
'Form' => array(
'userModel' => 'User',
'fields' => array('username' => 'email', 'password' => 'password')
)
)
));

UsersController.php - 登录函数 - 来自博客示例的 C&P

    if ($this->request->is('post')) {

if ($this->Auth->login()) {
//print_r($_SESSION);die();
return $this->redirect($this->Auth->redirectUrl());
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}

将打印预期的和整个 session 数组键=>值。完美的!!!现在,如果我让重定向通过。

CompaniesController.php

public function view($id = null) {
print_r($_SESSION);
}

不包含键=>值。

最佳答案

还有两个额外的项目要检查。经过这些修改后,Redis 与 Cake 2.6.4 完美配合。

1) 重新验证您的 phpinfo() 并确保没有本地 session 变量阻止全局 php.ini 设置。我的来自 httpd 的 php.conf。

2) 确实需要添加 session_start(),即使 CakePHP 文档声明如果使用 Session 或 Auth 的加载组件则不必使用此命令。我把命令放在 webroot 的第一行。

关于php - CakePHP 2.6,Redis session /缓存在重定向时被销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29904608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com