【问题标题】:redirect losses session cakephp重定向损失会话 cakephp
【发布时间】:2014-09-14 21:22:35
【问题描述】:

我正在尝试将会话保存在用户尝试输入的变量 url 中,如果用户未登录,因此我重定向到登录 URL,一旦成功登录,重定向回该网站曾要求。我的问题是它不保存会话变量或从一侧或另一侧。

这在 appController 中

if($this->action!='logout' && $this->action!='logout_cas' && $this->action!='login_cas' && $this->action!='login'){
        if(isset($_SESSION['cas_user'])){
            $_SESSION['url_user'] = Router::url('', true);
            $this->redirect(array('controller'=>'users','action'=>'login_cas'));
        }
    }

这在函数 login_cas 中的 UsersController 中

if ($this->Auth->user('active') != '1') {
                $active = $this->Auth->user('active');
                $this->Session->destroy();
                if($active < 0)
                    throw new Exception(__('Invalid user or password. Try again'));

                throw new Exception(__('User blocked, contact your administrator'));
            } else {
                $_SESSION["user_login_errors"] = 0;
                //$this->redirect(array('controller'=>'users','action'=>'home'));
                $this->redirect($_SESSION['url_user']);
            }

消息通知(8):未定义索引:url_user

【问题讨论】:

  • 不要直接访问 $_SESSION。为此,请使用 CakePHP 的会话组件和助手。但是我没有看到您发布的代码中出现任何问题。我会尝试发布更多您的代码。不过,为了澄清一下,当您说“重定向回已请求的网站”时,您只是在同一域的不同页面之间切换,对吗?
  • 当然,只有我的域网页。问题解决了,我的代码在其他存储库中运行良好,克隆了站点并重新开始工作。无论如何,请接受您的建议并接受 $ this-> Session-> 编写和阅读 CakePHP。谢谢!

标签: php session cakephp


【解决方案1】:

当然,只有我的域网页。问题解决了,我的代码在其他存储库中运行良好,克隆了站点并重新开始工作。无论如何,请接受您的建议并接受

$this->Session->write

并阅读 CakePHP。谢谢!

【讨论】:

    猜你喜欢
    • 2014-12-29
    • 2012-02-25
    • 2011-02-04
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多