1

How to destroy the session in codeigniter?

        error_reporting(0);
        $this->load->view('index');
        $this->load->database();
        $this->load->library('session');
        $this->load->helper(array('form','url'));
        $email    =$this->input->post("email");
        $password  =$this->input->post("password");
        $stmt = $this->db->query("select * from tbl_employees where email='".$email."' and password='".$password."'"); 
        $rowcount = $stmt->num_rows();
        if($rowcount==1) {
        foreach ($stmt->result() as $row)
        {
           $_SESSION['employee_id']=$row->employee_id;
           $_SESSION['first_name']=$row->first_name; 
           $_SESSION['last_name']=$row->last_name;
           print_r($_SESSION); 
           $this->session->sess_destroy();
           redirect('Dashboard/dashboard_index');
           $this->session->sess_destroy();
        }
Cœur
  • 37,241
  • 25
  • 195
  • 267
John
  • 68
  • 5
  • $this->session->sess_destroy(); or session_destroy(); for CI3 http://www.codeigniter.com/user_guide/libraries/sessions.html#destroying-a-session – José Trindade Sep 10 '15 at 17:43
  • 1
    What is the issue? You are destroying user session by `$this->session->sess_destroy();` so whats problem in it – Keval Rathi Sep 11 '15 at 05:32
  • it's is not destroying the session – John Sep 11 '15 at 06:03
  • Why do you say it is *not* destroying the session? What happens instead? – wallyk Sep 11 '15 at 07:34
  • 1
    Also, please **do not** store passwords in plaintext. Always store their hash. See [this](http://stackoverflow.com/questions/549/the-definitive-guide-to-form-based-website-authentication/477578#477578). – wallyk Sep 11 '15 at 07:38
  • possible duplicate of [Codeigniter unset session](http://stackoverflow.com/questions/14233595/codeigniter-unset-session) – Keith M Sep 12 '15 at 00:34

1 Answers1

1

Read this: Session Class

Note: The Session class does not utilize native PHP sessions. It generates its own session data, offering more flexibility for developers.

This is a wrong use codeigniter:

$_SESSION['employee_id']=$row->employee_id;

Try this:

$this->session->set_userdata('employee_id', $row->employee_id);