CodeIgniter Forums
its a bug? session library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: its a bug? session library (/showthread.php?tid=5403)



its a bug? session library - El Forum - 01-20-2008

[eluser]alebenson[/eluser]
hi there!
i was doing something with sessions and i got this error
Message: Cannot modify header information - headers already sent by...

i look it up in the forum and everyone said that is the space before ?> or an echo... so i made test to discard those things

1_first

Code:
class Test extends Controller {
    
function index()
{
    $this->load->library('session');
    $check = $this->session->userdata('session_id');
    if ($check == FALSE)
    {
        echo 'FALSE FALSE FALSE';
    }
    else
    {
        echo 'OK! OK! OK!';
    }
}
}

result OK! OK! OK!


2_second

Code:
class Test extends Controller {
    
function index()
{
    $this->load->library('session');
    $this->session->sess_destroy(); //// NEW LINE HERE
    $check = $this->session->userdata('session_id');
    if ($check == FALSE)
    {
        echo 'FALSE FALSE FALSE';
    }
    else
    {
        echo 'OK! OK! OK!';
    }
}
}

result OK! OK! OK!

same results
well i dont get the error... but i dont understand why i get the same result after a kill the session


its a bug? session library - El Forum - 01-21-2008

[eluser]rafsoaken[/eluser]
I had a look into the source of library/Session.php of the svn version (CI 1.60), and it seems that $this->session->userdata is just not reset when you execute $this->session->sess_destroy().

In the controller you'd have to do either something like:
Code:
$this->session->sess_destroy();
$this->session->userdata=array();
or create a new session - the old one gets deleted along with its data:
Code:
$this->session->sess_create();
In the 2nd case of course, you'd have again a session_id.


its a bug? session library - El Forum - 01-21-2008

[eluser]Pascal Kriete[/eluser]
sess_destroy() simply moves the cookie timestamp to the past, so that it will be deleted when the page is reloaded. So it does get cleared, but no right away.

If you only have that one variable you could use unset_userdata().


its a bug? session library - El Forum - 01-21-2008

[eluser]alebenson[/eluser]
ok is working now.

but to test a set_userdata i have to do another function that test it
if i do it in the same scrip i get the error header message

thanks