title: Why i am getting previous session data for current session in codeiginitor even after destroying previous session
body: <p>I am facing problem in function <code>profile()</code>. In this method I am fetching data from email using session.</p>
  
  <p>When I login, displaying current data. But when I click on profile it displays previous session data and after refresh it become current session data.
  <img src="https://i.stack.imgur.com/7q7fZ.png" alt="enter image description here"> 
  last session data</p>
  
  <p>after refresh display current session
  <img src="https://i.stack.imgur.com/UA4W7.png" alt="enter image description here"></p>
  
  <p>my controller file is <code>admin.php</code>.</p>
  
  <p><strong>admin.php</strong></p>
  
  <pre><code>&lt;?php 
  class Admin extends CI_Controller{
  
      function __construct(){
          parent::__construct();
  
          // Load form helper library
          $this-&gt;load-&gt;helper('form');
          //Load foam valodation library
          $this-&gt;load-&gt;library('form_validation');
          // Load the model
             $this-&gt;load-&gt;model('adminmodel');
      }
  
      public function index(){
  
          // Load our view to be displayed        
          $this-&gt;load-&gt;view('admin/login');
      }
  
  // Check for Admin login process    
      public function dashboard(){        
  
          // Validate the user can login      
          $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required');
  
            if ($this-&gt;form_validation-&gt;run() == FALSE)   //checking validation
            {         
              if(isset($this-&gt;session-&gt;userdata['logged_in']))
              {
                  $this-&gt;load-&gt;view('admin/dashboard');
              }
              else
              {
                  $this-&gt;load-&gt;view('admin/login');
              }           
            } 
  
           else
           {   //validation are true                           
              if (isset($_POST['login']))
              {
                  $email = $this-&gt;input-&gt;post('email');
                  $password =$this-&gt;input-&gt;post('password');
                  // Validate the admin can login
                  $result = $this-&gt;adminmodel-&gt;validate($email,$password);
                  if ($result) {//if the user credidential is validated
                      $data = array(
                              'email' =&gt; $this-&gt;input-&gt;post('email'),
                              'is_logged_in' =&gt; true
                      );
                      print_r($data);
                  }
                  // Add user data in session
                  $this-&gt;session-&gt;set_userdata($data);
                  //load dashboard and passing value
                  $this-&gt;load-&gt;view('admin/dashboard',$result);
              }
           }
      } //end of dashboard
  
      public function profile(){
          if($this-&gt;session-&gt;userdata('is_logged_in')){
          $email = $this-&gt;session-&gt;userdata('email');
          $result = $this-&gt;adminmodel-&gt;fetchdata($email);
          print_r($result);
          $this-&gt;load-&gt;view('admin/profile',$result);
          }
          else
          {
              echo "failed profile";
          }
  
      } // end of profile 
  
      // Logout from admin page
      public function logout() {
  
          // Removing session data
          $sess_array = array(
                  'email' =&gt; '',
                  'is_logged_in'=&gt;false               
                             );
          $this-&gt;session-&gt;unset_userdata($sess_array);
          $data['message_display'] = 'Successfully Logout';
          $this-&gt;load-&gt;view('admin/login', $data);
      }
  
  }
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>model file</strong></p>
  
  <p>adminmodel.php</p>
  
  <pre><code>&lt;?php
  class Adminmodel extends CI_Model{
  
          public function validate($email,$password)
          {   
            $query = $this-&gt;db-&gt;where(['email'=&gt;$email,'password'=&gt;$password])
                             -&gt;from('login')                
                             -&gt;get();               
             $result = $query-&gt;row();
              return $result;     
           }
  
           public function fetchdata($email)
           {
              $query = $this-&gt;db-&gt;where(['email'=&gt;$email])
              -&gt;from('login')
              -&gt;get();
              $result = $query-&gt;row();
              return $result;
           }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>profile.php</strong></p>
  
  <pre><code>&lt;?php
  
  echo " I am in Profile " . $email;
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Profile&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;p&gt;Name : &lt;input type = "text" value="&lt;?php echo $name; ?&gt;" /&gt;&lt;p&gt;
      &lt;p&gt;Mobile : &lt;input type = "text" value="&lt;?php echo $mobile; ?&gt;" /&gt; &lt;/p&gt;
      &lt;p&gt;Address : &lt;input type = "text" value="&lt;?php echo $address; ?&gt;" /&gt; &lt;/p&gt;
      &lt;p&gt;Email : &lt;input type = "text" value=" &lt;?php echo $email;?&gt;" /&gt; &lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>