CodeIgniter Forums
simple session question? - 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: simple session question? (/showthread.php?tid=35533)



simple session question? - El Forum - 11-02-2010

[eluser]anna16[/eluser]
Hi guys

I just created a simple demonstration of session using CodeIgniter.
Anyway here is the link below,
http://coder9.com/ci/ztest.php/session/session/session_view/

If you try to enter a username and email address.
and press the submit button it's working fine but
when you click the logout link the username and email data
don't disappear. Unless you click it twice.
Why is this?

By the way below is the codes for my controller,
Code:
<?php

class Session extends Controller
{
    function __construct()
    {
        parent::Controller();
        $this->load->library('session');
        $this->load->helper('form');
    $this->load->helper('url');
    }

  function session_view()
  {
    $this->load->view('session/session_form');  
  }

  // validate some data
    function validate_data()
    {
        $this->load->library('form_validation');
      //load session
      $data = array(
                  'username'  => $_POST['username'],
                  'email'     => $_POST['email'],
                  'logged_in' => TRUE
               );

      $this->session->set_userdata($data);      
    
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('session/session_form');
        }
        else
        {
            $this->load->view('session/login_area');
        }      
  }
  
  function session_form()
  {
            $this->load->view('session/session_form');  
  }
  
  function page_one()
  {
            $this->load->view('session/page_one');    
  }

  function page_two()
  {
            $this->load->view('session/page_two');  
  }
  
  function logout()
  {
    $this->session->sess_destroy();
        $this->load->view('session/session_form');      
  }  
}
// end of site class


THanks in advanced.


simple session question? - El Forum - 11-02-2010

[eluser]LuckyFella73[/eluser]
I think the session data is still available untill the next page load.
Try to make a redirect to the "session_form" page.


simple session question? - El Forum - 11-02-2010

[eluser]anna16[/eluser]
@luckyfella73

Nice it works.
Where did you learned that trick? XD


simple session question? - El Forum - 11-02-2010

[eluser]LuckyFella73[/eluser]
Quote:Where did you learned that trick? XD
he he!

Nearly all I know about cookies and sessions I learned from
WanWizard. He did a lot informative posts about that.

Nice your code works now!