2015-05-19 31 views
0

我是cakephp中的新成員。我使用2.5版本。我在註銷功能方面有問題。代碼

$this->Session->destroy(); 

如果我在退出會話後點擊後退按鈕,那麼歡迎頁面出現,在我的代碼中不工作。刷新歡迎頁面後,會話將破壞..這是我的問題會話。

public function logout(){ 

    $this->Session->delete('username'); 
    if($this->Session->destroy()) { 
echo $this->Session->setFlash("Congrats, you have successfully logged Out"); 
    $this->redirect('/users/login'); 
    }else{ 
echo $this->Session->setFlash("you failed in log Out"); 
    } 

} 

回答

0

如果您使用的是Auth,您只需調用Auth註銷功能即可。即

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

否則你可以銷燬會話或cookie。

public function logout(){ 
    $this->Session->destroy(); 
    $this->Cookie->destroy(); 
    $this->Session->setFlash('Congrats, you have successfully logged Out.'); 
    return $this->redirect('/users/login'); 
}