Welcome Guest, Not a member yet? Register   Sign In
simple session question?
#1

[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/s...sion_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.
#2

[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.
#3

[eluser]anna16[/eluser]
@luckyfella73

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

[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!




Theme © iAndrew 2016 - Forum software by © MyBB