in my logout function i like to destroy all session except one here is my function :
public function out(){
$ref = $this->session->userdata('ref');
var_dump($ref);
$this->session->sess_destroy();
$this->session->set_userdata('ref', $ref );
$ref = $this->session->userdata('ref');
echo '---------------------------------------<br />';
var_dump($ref);
}
but this doesnt work and it destroys all the session even ref
and when i check ref
in the next page i get null
inn the function page i get this output :
array (size=2)
'val' => int 666
'date' => int 1397060477
---------------------------------------
array (size=2)
'val' => int 666
'date' => int 1397060477
A PHP Error was encountered
Severity: Notice
Message: Undefined index: last_activity
Filename: drivers/Session_cookie.php
Line Number: 590
Backtrace:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: session_id
Filename: drivers/Session_cookie.php
Line Number: 611
Backtrace:
im using 3.0-dev
Try this:
public function out(){
$ref = $this->session->userdata('ref');
$this->session->sess_destroy(); // this kills the ID/cookie
$this->session->sess_create(); // properly start a new session with new ID/cookie
if($ref)
$this->session->set_userdata('ref', $ref );
redirect(base_url().'index');
}
Note:
sess_create()
is not documented here: CodeIgniter Sessions
You have to look at /system/libraries/Session.php
to find sess_create()
UPDATE
When using Dev 3.0 then you need to do this:
$this->session->__construct();
Session is destroyed yet not recreated after destruction. Perhaps your session class should have a session_start in the constructor
After you destroy a session, I believe it would be this line:
$this->session->sess_destroy();
You have no session at all, so you can't put anything to it.
You first store session variables in variable $ref, then you destroy whole session, and again trying to put something in session. So after destroy, you have to start another session. Something like this:
public function out(){
$ref = $this->session->userdata('ref');
$this->session->sess_destroy();
session_start(); // put ur session_start func here
if($ref)
$this->session->set_userdata('ref', $ref );
redirect(base_url().'index');
}
thanx guys , i've solved it by loading session libe manully in the function after destroyin it ... even though i'm auto loading sess lib !
i guess they never going to solve sess lib problems !
public function out(){
$ref = $this->session->userdata('ref');
$this->session->sess_destroy();
$this->load->library('session');
$this->session->set_userdata('ref', $ref );
redirect(base_url().'index');
}