title: How to use session table in code igniter
body: <p>I'm new on code igniter and wanna ask how to use session with session table in database. 
  I have create session table with this sctructure. </p>
  
  <pre><code>CREATE TABLE `sys_sessions` (
      `session_id` VARCHAR(40) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
      `ip_address` VARCHAR(16) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
      `user_agent` VARCHAR(50) NOT NULL COLLATE 'utf8_unicode_ci',
      `last_activity` INT(10) UNSIGNED NOT NULL DEFAULT '0',
      `user_data` TEXT NOT NULL COLLATE 'utf8_unicode_ci',
      PRIMARY KEY (`session_id`)
  )
  COLLATE='utf8_unicode_ci'
  ENGINE=InnoDB;
  </code></pre>
  
  <p>and use two controller to test session used. First I run set_session_test() controller.</p>
  
  <pre><code>public function set_session_test()
  {
     $this-&gt;load-&gt;library('session');
     $this-&gt;session-&gt;set_userdata('username', 'Jhon');
     $this-&gt;session-&gt;set_userdata('email', 'jhon@gmail.com');
     echo "&lt;pre&gt;"; print_r($this-&gt;session-&gt;all_userdata()); echo "&lt;/pre&gt;";
  }
  </code></pre>
  
  <p>And the result </p>
  
  <pre><code>Array
  (
      [session_id] =&gt; dd7e0e2266da6481ef45faaa7e3c808b
      [ip_address] =&gt; 127.0.0.1
      [user_agent] =&gt; Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
      [last_activity] =&gt; 1387619782
      [user_data] =&gt; 
      [username] =&gt; Jhon
      [email] =&gt; jhon@gmail.com
  )
  </code></pre>
  
  <p>then I run get_session_test() to check if it session value could be still there. </p>
  
  <pre><code>public function get_session_test()
  {
     $this-&gt;load-&gt;library('session');
     $this-&gt;session-&gt;userdata('username');
     $this-&gt;session-&gt;userdata('email');
     echo "&lt;pre&gt;"; print_r($this-&gt;session-&gt;all_userdata()); echo "&lt;/pre&gt;";
  }
  </code></pre>
  
  <p>And the result is </p>
  
  <pre><code>Array
  (
      [session_id] =&gt; 1b10e3671728804a63266bb9295b7e5d
      [ip_address] =&gt; 127.0.0.1
      [user_agent] =&gt; Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
      [last_activity] =&gt; 1387619831
      [user_data] =&gt; 
  )
  </code></pre>
  
  <p>Unfortunately, I didn't found any username and email session that i stored. And i check table sys_session, it creates two row of session_id. The question is </p>
  
  <ol>
  <li>Is it common behaviour of ci session?</li>
  <li>So, How to use set and get custom field with CI table session?</li>
  <li>Why the created custom field always lost after I move to another page?</li>
  <li>When I run this->session->sess_destroy(), why it is not remove any session in table session?</li>
  </ol>
  
  <p>Thx in advance..</p>