0

i want session destroy logout but they don't work properly.

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
  • 1
    sess_destroy not ses_destroy
    – Anigel
    Jun 26, 2013 at 10:14

5 Answers 5

1

You have typo. According to CodeIginiter-2 documentation, the method for destroying the sessions is sess_destroy, not ses_destroy.

0

Because some spelling mistake in your controller.

$this->session->ses_destroy(); replace $this->session->sess_destroy();

read sentence properly link is : http://ellislab.com/codeigniter/user-guide/libraries/sessions.html check this link.

0
0

Typo error exist sess_destroy

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

You are having an spell miskate in you controller.
$this->session->sess_destroy()
instead of
$this->session->ses_destroy()

Please check below example to avoid your confusion:


    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

Do like this,

First store username and password detail in your session like this

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

And then for session destroy use this code,

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.