如何杀死cakephp中的会话

时间:2011-02-11 07:25:08

标签: cakephp cakephp-1.3

我正在使用登录模块。在注销功能中,我按如下方式编写代码,首先终止会话,然后将其重定向到主页。它工作正常但会话没有破坏。 如果有人知道请帮助我 这是我登录的代码片段&注销:

function login()
{

   if(!empty($this->data))
    { 

       $user1= $this->User->validateLogin($this->data['User']);

         if($user1== true)
        {

               $this->redirect(array('action'=>'index'));
        }
        else
        {
                $this->Session->setflash('Login failed, Try again'); 
         }
    }
}

function logout()
{

    $this->Session->delete('User');
    $this->redirect('/users/index');
}

我得到的信息是,我必须保留标题信息,下面是我的代码片段: $ this-> header(“Cache-Control:no-cache,no-store,must-revalidate”); $ this-> header(“Expires:Mon,1970年1月1日00:00:00 GMT”);

但是我没有得到我的控制器的哪一部分我应该粘贴这段代码?请帮帮我......

3 个答案:

答案 0 :(得分:8)

尝试$ this-> Session-> destroy(); destroy方法将删除会话cookie和存储在临时文件系统中的所有会话数据。检查此link

答案 1 :(得分:2)

您正在重定向,因为它不被允许,而不是因为您的注销功能中的重定向。您还需要在控制器的beforefilter(CakePHP 2)中允许使用注销功能:

$this->allow('logout');

答案 2 :(得分:1)

你不想杀死这个会话。只记录用户!

$this->Session->delete('Auth');

否则你会破坏cookie和其他用户定义的设置,这些设置非常烦人(语言,......)

但官方的蛋糕方式是:

$this->redirect($this->Auth->logout());
相关问题