【问题标题】:cakephp 3.2 $this->Auth->redirectUrl() always returns "\" on production server - Sessioncakephp 3.2 $this->Auth->redirectUrl() 总是在生产服务器上返回“\” - 会话
【发布时间】:2016-10-12 12:48:51
【问题描述】:

我创建了具有登录功能的 Cakephp 3 应用程序。登录功能在我的本地机器上完美运行。但是,在生产服务器上,当登录凭据正确时,它会将我重定向到“\”而不是我指定的 URL。我相信这是会话的问题。我的意思是由于某种原因会话在重定向行丢失。

守则:

AppController的初始化方法

public function initialize()
{
    parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
    $this->loadComponent('Auth',[
            'authenticate'=>[
                    'Form'=>[
                            'fields'=>[
                                    'username'=>'username',
                                    'password'=>'password'
                            ],
                            'finder' => 'auth',
                    ]
            ],
            'loginAction'=>[
                    'controller'=>'Users',
                    'action'=>'login'
            ],
            'loginRedirect' => [
                    'controller'=> 'Pages',
                    'action'=> 'dashboard'
            ],
    ]);
}

UserController.php:

class UsersController extends AppController {


public function initialize()
{
    parent::initialize();
}

public function login() {
    if ($this->request->is('post')) {
        $user=$this->Auth->identify();     
        if($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        } else {
            $this->Flash->error(_('your username or password is incorrect, please try agian'), [
                'key' => 'falseSignIn']);
        }
    }
}
public function logout() {
    return $this->redirect($this->Auth->logout());
}

}

这是我使用 phpinfo() 的会话信息;

【问题讨论】:

  • 你能告诉我你定义了loginredirect的应用控制器的初始化函数吗?
  • 我在主要问题中添加了。请看那里

标签: session authentication cakephp-3.0 url-redirection production-environment


【解决方案1】:

您需要创建一个隐藏的文本框并将 $this->Auth->redirectUrl() 的值分配给它。然后您可以从表单中检索文本框的值,并将其作为参数传递给 $this->redirect()。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 2018-08-05
    相关资源
    最近更新 更多