user1337900
user1337900

Reputation: 1

Session destroy in codeigniter

I am using Code igniter for my application. I have three controllers and three models in may application homepage,dashboard and settings.I have started the session in homepage model and wanted destroy it in dashboard controller. here is my code

foreach($query->result(as $row) {
   $info = array(
       'loginid'    => $row->loginid,
       'firstname'  => $row->firstname,
       'emailid'    => $row->emailid,
       'logged_in'  => TRUE
   );
}

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

but my session array is not getting displyed in dashboard controller.

How I should destroy the session?

Upvotes: 0

Views: 105

Answers (4)

Dev
Dev

Reputation: 74

$this->session->set_userdata([
                    'logged_in'  => TRUE
                    'loginid'    => $row->loginid,
                    'firstname'  => $row->firstname,
                    'emailid'    => $row->emailid,       
                ]);

And in your conntroller to unset like this

$this->session->set_userdata([
            'logged_in' => false,
            'loginid' => null
        ]);

Upvotes: 0

Sachin Sudhakar Sonawane
Sachin Sudhakar Sonawane

Reputation: 1917

foreach($query->result(as $row) Wrong

Please use

foreach($query->result() as $row)
{
    $info = array( 
                'loginid'  => $row->loginid ,
                'emailid' => row->emailid,
           );
}

To display in dashboard controller. Try this

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

Then you can destroy session by

$this->session->sess_destroy();

Upvotes: 0

Matt
Matt

Reputation: 9433

You destroy the session with:

$this->session->sess_destroy();

as per the codeigniter session documentation.

That said, I'm not sure how it's related to the code you posted and I'm pretty sure it won't work.

Upvotes: 0

mlinuxgada
mlinuxgada

Reputation: 590

Try this:

$this->session->sess_destroy();

Upvotes: 1

Related Questions