title: Codeigniter session clear on login
body: <p>I save preferences of anonymous user in sessions.The issue is that when user did login,I have to clear previous sessions and start new one(for security reasons).</p>
  
  <p>It seems if I destroy session, then login function would do logout! Even though I use <code>set_userdata</code> after <code>sess_destroy</code> it cannot do login (maybe session after destruction becomes unusable).
  Using <code>unset</code> acts only on a few specified sessions.Is there any way to clear all sessions of the user without such a problem?</p>
  
  <pre><code>public function login()
  {
      if($this-&gt;session-&gt;userdata('id'))
          redirect($this-&gt;config-&gt;base_url());
      if($_POST)
      {
          ...
          $user=...
          if($user)
          {
              $this-&gt;session-&gt;sess_destroy();
              $this-&gt;session-&gt;set_userdata('id',$user['id']);
              ....
          }
          else
          {
              ....    
          }
      }
      $this-&gt;load-&gt;view('...');
  }
  </code></pre>