PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

[FIXED] Why can't the session be unset and destroyed?

 January 30, 2022     codeigniter, php, session     No comments   

Issue

I have an almost working registration system on my website, the only part missing is the logout function. It starts the session but doesn't seem to destroy it, therefore, the previous session is always active. Am I destroying the session correctly or am I doing something entirely wrong?

At first, I just tried setting the user data and then unsetting them one by one before destroying the session, that didn't work. So now I set the user data with plain strings before destroying them, again, doesn't seem to work.

the logout link looks like this:

<a href="http://localhost/dir/dir1/dir2/index.php/Controller/logout">logout</a>

In my controller I have this:

public function logout() {


    $this->load->helper('url');
    $this->load->library('session');

    $session_data = array(
      'data' =>  'data',
      'data' => 'data',
      'data' =>  'data',
      'data' =>  'data',
      'data' =>  'data',
      'data' => 'data',
      'data' => 'data',
      'data' => 'data',
      'data' => 'data',
      'data' =>  'data',
      'data' =>  'data',
      'data' =>  'data',
      'data' =>  'data',
      'data' =>  'data'
    );
    $this->session->set_userdata($session_data);

        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');
        $this->session->unset_userdata('data');

    $this->session->sess_destroy();
    redirect('http://localhost/dir/dir1/dir2/index.php/Controller/loginview', 'refresh');
}

I expect the session to be destroyed before it redirects(which it does), yet when I type in the new login credentials it still shows the ones from the previous session, it should instead show the new ones.


Solution

I simply forgot to specify the session parameters, anyways problem solved!



Answered By - frogman578
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing