1

我开发了一个简单的 Cake 应用程序,在完成编码后,我将它上传到我的 Web 服务器,现在它有几个问题(它在 localhost 上就像一个魅力):

  • setFlash消息不起作用(我在数据库中使用会话,并且有一些会话的记录cake_sessions
  • 成功登录后,它会再次将我重定向到登录页面。
  • 有时缓存文件会消失!(我的tmp文件夹是可写的)

实际上,在登录之前不允许任何操作,但您应该You are not authorized to access that location.在登录页面顶部看到一条闪烁消息,但它不会出现,但是如果您使用错误的用户名/密码登录,它会显示一条消息(wth?

UsersController 的登录和注销方法:

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash(__('Invalid username or password, try again'));
        }
    }
}

public function logout() {
    $this->redirect($this->Auth->logout());
}

最近执行的 100 个查询(来自日志):

SELECT `Session`.`id`, `Session`.`data`, `Session`.`expires` FROM `srv`.`cake_sessions` AS `Session` WHERE `id` = '7orjo8clp192qeie55k6pqro26' LIMIT 1
4

2 回答 2

1

听起来您的网络服务器上的会话已损坏。检查您的系统时钟 - 如果相差超过几分钟,您的会话将很快过期,如果不是立即过期

于 2012-09-28T22:38:36.887 回答
0

确保在用户模型中为登录设置了组件。它应该是这样的

 public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'desired_controller', 'action' => 'desired_action'),
        'logoutRedirect' => array('controller' => 'desired_controller', 'action' => 'display', 'home')
    )
);

还要检查以确保您正确设置了 beforeFilter

//UsersController

  public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow('add', 'logout', 'other_actions');
}

编辑

这似乎与您所描述的非常相似cakephp 登录页面无处可去

考虑到奇怪的行为,这也可能值得一试

https://github.com/cakephp/cakephp/commit/c96e364cbb6ec8dd72dd220836a07ed104d2d50a。它修复了会话的错误到期

于 2012-09-28T14:28:34.277 回答