EllisLab text mark
Advanced Search
     
Session Class -> sess_destroy not removing session
Posted: 25 October 2012 03:35 PM   [ Ignore ]
Joined: 2012-10-25
11 posts

I’ll preface by saying I’m relatively new to CodeIgniter, so I could just be doing something wrong.

I’m calling $this->session->sess_destroy(); before any output; However, throughout the same page load I can still call $this->session->userdata(‘id’); and get the ‘correct’ information back. If I use $this->session->unset_userdata(‘id’); instead of sess_destroy(); everything works as I would expect and I get no data returned.

This is for a user logout and should therefore unset all userdata before continuing with the output. Is this not possible with CI sessions? To be honest, I’m not entirely convinced I should be using them over standard $_SESSION

Thanks in advance for any help / advice.

[Edit] This is Chrome 22 on Ubuntu 12.04

 
Posted: 25 October 2012 03:56 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2012-10-23
58 posts

Use [ code ][ /code ] tags to insert your code.

I usually use like this:

$this->session->sess_destroy();
redirect('any_function'); 

Hope it helps!

Also you can control user do not go back after logout.

 

 
Posted: 25 October 2012 04:07 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-10-25
11 posts

So a redirect is required? I’ve tested and it certainly works around the problem. Hmm. Thanks for the pointer - it wasn’t expected behaviour.

 
Posted: 25 October 2012 04:14 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2012-10-23
58 posts
Aeisor - 25 October 2012 04:07 PM

So a redirect is required? I’ve tested and it certainly works around the problem. Hmm. Thanks for the pointer - it wasn’t expected behaviour.

Al least all my time programming with CI I’ve used always redirect after $this->session->destroy()

Glad it helps dude!

 
Posted: 31 October 2012 11:03 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2011-10-12
102 posts

A redirect is required because the session (native php) only is destroyed by the next request.

 Signature 

SMC - full CRUD Model for CodeIgniter:
forum: http://codeigniter.com/forums/viewthread/223845/

 
Posted: 31 October 2012 03:10 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2010-01-28
228 posts

Add this in your constructor:

<?php
$this
->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
?>