2013-06-26 235 views
0

我想會話銷燬註銷但它們無法正常工作。註銷時未銷燬會話

CONTROLLER

public function logout(){ 
      $this->session->ses_destroy(); 
      redirect('users/index'); 
     } 

VIEW

<ul class="dropdown-menu"> 
    <li><a href="javascript:;">My Profile</a></li> 
    <li><a href="javascript:;">My Groups</a></li> 
    <li class="divider"></li> 
    <li><a href="<?php echo base_url().'Users/logout' ?>">Logout</a></li> 
</ul> 

RESULT

Fatal error: Call to undefined method CI_Session::ses_destroy() 
+1

sess_destroy不ses_destroy – Anigel

回答

0

錯字錯誤存在sess_destroy

public function logout(){ 
      $this->session->sess_destroy(); 
      redirect('users/index'); 
     } 
0

你在控制器中有拼寫錯誤。 $這 - >會話級> sess_destroy而不是
()

$這個 - >會話級> ses_destroy()

請檢查下面的例子避免你的困惑:

 

    class Home extends CI_Controller 
    { 
     function __construct() 
     { 
      parent::__construct(); 
      //this condition checks the existence of session if user is not accessing 
      //login method as it can be accessed without user session 
      if(!$this->session->userdata('logged_in') && $this->router->method != 'login') { 
       redirect('login'); 
      } 
     } 
     function index() 
     { 
      $session_data = $this->session->userdata('logged_in'); 
      $data['email'] = $session_data['email']; 
      $this->load->view('home_view', $data); 
      $this->load->view('home_content_view', $data); 
     } 

     function logout() 
     { 
      $this->session->userdata = array(); 
      $this->session->sess_destroy(); 
      redirect('home', 'refresh'); 
     } 
    } 

0

這樣做,

首先在你的會話中存儲這樣的用戶名和密碼的細節

$this->session->set_userdata($this->data); 

然後會話銷燬使用此代碼,

public function logout(){ 
    $this->session->sess_destroy(); 
    redirect(base_url().''); 
    }