title: Error codeigniter generates multiple sessions for the same user
body: <p>I'm a novice in this framework. But create a project with codeigniter 3.19 and Ion Auth 3 as a method of authentication and user registration.</p>
  
  <p>on my local server xampp windows, it works perfectly generates a session for each user. But in my web linux ubuntu 16.04, vestacp, with cloudflare, I generate 10 sessions every 1 sg constantly having millions of session records and taking into account that I have very little traffic I assume it is an error that creates duplicate sessions for each user.</p>
  
  <p>session capture in all fields ip_address gives me the ip of my server.</p>
  
  <p><a href="https://i.stack.imgur.com/AKfPo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AKfPo.jpg" alt="enter image description here"></a>
  web to verify the problem tvglu.net
  attached configurations, very grateful any help.</p>
  
  <pre><code>/application/config/config.php 
  
  $config['sess_driver'] = 'database'; 
  $config['sess_cookie_name'] = 'cisession'; 
  $config['sess_expiration'] = 7200; 
  $config['sess_save_path'] = 'ci_session'; 
  $config['sess_match_ip'] = FALSE; 
  $config['sess_time_to_update'] = 300; 
  $config['sess_regenerate_destroy'] = FALSE; 
  
  $config['cookie_prefix']    = 'cisession'; 
  $config['cookie_domain']    = ''; 
  $config['cookie_path']        = '/'; 
  $config['cookie_secure']    = FALSE; 
  $config['cookie_httponly']     = FALSE; 
  
  $config['proxy_ips'] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '';
  /application/config/autoload.php 
  
  $autoload['libraries'] = array('ion_auth'); 
  
  tabla base de datos 
  
  CREATE TABLE `ci_session` ( 
   `id` varchar(128) NOT NULL, 
   `ip_address` varchar(45) NOT NULL, 
   `timestamp` int(10) unsigned NOT NULL DEFAULT '0', 
   `data` blob NOT NULL, 
   PRIMARY KEY (`id`), 
   KEY `ci_sessions_timestamp` (`timestamp`) 
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  
  /application/libraries/Ion_auth.php 
  
  &lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
  
  class Ion_auth 
  { 
      /** 
       * account status ('not_activated', etc ...) 
       * 
       * @var string 
       **/ 
      protected $status; 
  
      /** 
       * extra where 
       * 
       * @var array 
       **/ 
      public $_extra_where = array(); 
  
      /** 
       * extra set 
       * 
       * @var array 
       **/ 
      public $_extra_set = array(); 
  
      /** 
       * caching of users and their groups 
       * 
       * @var array 
       **/ 
      public $_cache_user_in_group; 
  
      /** 
       * __construct 
       * 
       * @return void 
       * @author Ben 
       **/ 
      public function __construct() 
      { 
          $this-&gt;load-&gt;config('ion_auth', TRUE); 
          $this-&gt;load-&gt;library(array('email')); 
          $this-&gt;lang-&gt;load('ion_auth'); 
          $this-&gt;load-&gt;helper(array('cookie', 'language','url')); 
  
          $this-&gt;load-&gt;library('session'); 
  
          $this-&gt;load-&gt;model('ion_auth_model'); 
  
          $this-&gt;_cache_user_in_group =&amp; $this-&gt;ion_auth_model-&gt;_cache_user_in_group; 
  
          //auto-login the user if they are remembered 
          if (!$this-&gt;logged_in() &amp;&amp; get_cookie($this-&gt;config-&gt;item('identity_cookie_name', 'ion_auth')) &amp;&amp; get_cookie($this-&gt;config-&gt;item('remember_cookie_name', 'ion_auth'))) 
          { 
              $this-&gt;ion_auth_model-&gt;login_remembered_user(); 
          } 
  
          $email_config = $this-&gt;config-&gt;item('email_config', 'ion_auth'); 
  
          if ($this-&gt;config-&gt;item('use_ci_email', 'ion_auth') &amp;&amp; isset($email_config) &amp;&amp; is_array($email_config)) 
          { 
              $this-&gt;email-&gt;initialize($email_config); 
          } 
  
          $this-&gt;ion_auth_model-&gt;trigger_events('library_constructor'); 
      } 
  
      /** 
       * __call 
       * 
       * Acts as a simple way to call model methods without loads of stupid alias' 
       * 
       **/ 
      public function __call($method, $arguments) 
      { 
          if (!method_exists( $this-&gt;ion_auth_model, $method) ) 
          { 
              throw new Exception('Undefined method Ion_auth::' . $method . '() called'); 
          } 
          if($method == 'create_user') 
          { 
              return call_user_func_array(array($this, 'register'), $arguments); 
          } 
          if($method=='update_user') 
          { 
              return call_user_func_array(array($this, 'update'), $arguments); 
          } 
          return call_user_func_array( array($this-&gt;ion_auth_model, $method), $arguments); 
      } 
  
      /** 
       * __get 
       * 
       * Enables the use of CI super-global without having to define an extra variable. 
       * 
       * I can't remember where I first saw this, so thank you if you are the original author. -Militis 
       * 
       * [MENTION=178865]Access[/MENTION]    public 
       * @param    $var 
       * @return    mixed 
       */ 
      public function __get($var) 
      { 
          return get_instance()-&gt;$var; 
      } 
  
  
      /** 
       * forgotten password feature 
       * 
       * @return mixed  boolian / array 
       * @author Mathew 
       **/ 
      public function forgotten_password($identity)    //changed $email to $identity 
      { 
          if ( $this-&gt;ion_auth_model-&gt;forgotten_password($identity) )   //changed 
          { 
              // Get user information 
              $user = $this-&gt;where($this-&gt;config-&gt;item('identity', 'ion_auth'), $identity)-&gt;where('active', 1)-&gt;users()-&gt;row();  //changed to get_user_by_identity from email 
  
              if ($user) 
              { 
                  $data = array( 
                      'identity'        =&gt; $user-&gt;{$this-&gt;config-&gt;item('identity', 'ion_auth')}, 
                      'forgotten_password_code' =&gt; $user-&gt;forgotten_password_code 
                  ); 
  
                  if(!$this-&gt;config-&gt;item('use_ci_email', 'ion_auth')) 
                  { 
                      $this-&gt;set_message('forgot_password_successful'); 
                      return $data; 
                  } 
                  else 
                  { 
                      $message = $this-&gt;load-&gt;view($this-&gt;config-&gt;item('email_templates', 'ion_auth').$this-&gt;config-&gt;item('email_forgot_password', 'ion_auth'), $data, true); 
                      $this-&gt;email-&gt;clear(); 
                      $this-&gt;email-&gt;from($this-&gt;config-&gt;item('admin_email', 'ion_auth'), $this-&gt;config-&gt;item('site_title', 'ion_auth')); 
                      $this-&gt;email-&gt;to($user-&gt;email); 
                      $this-&gt;email-&gt;subject($this-&gt;config-&gt;item('site_title', 'ion_auth') . ' - ' . $this-&gt;lang-&gt;line('email_forgotten_password_subject')); 
                      $this-&gt;email-&gt;message($message); 
  
                      if ($this-&gt;email-&gt;send()) 
                      { 
                          $this-&gt;set_message('forgot_password_successful'); 
                          return TRUE; 
                      } 
                      else 
                      { 
                          $this-&gt;set_error('forgot_password_unsuccessful'); 
                          return FALSE; 
                      } 
                  } 
              } 
              else 
              { 
                  $this-&gt;set_error('forgot_password_unsuccessful'); 
                  return FALSE; 
              } 
          } 
          else 
          { 
              $this-&gt;set_error('forgot_password_unsuccessful'); 
              return FALSE; 
          } 
      } 
  
      /** 
       * forgotten_password_complete 
       * 
       * @return void 
       * @author Mathew 
       **/ 
      public function forgotten_password_complete($code) 
      { 
          $this-&gt;ion_auth_model-&gt;trigger_events('pre_password_change'); 
  
          $identity = $this-&gt;config-&gt;item('identity', 'ion_auth'); 
          $profile  = $this-&gt;where('forgotten_password_code', $code)-&gt;users()-&gt;row(); //pass the code to profile 
  
          if (!$profile) 
          { 
              $this-&gt;ion_auth_model-&gt;trigger_events(array('post_password_change', 'password_change_unsuccessful')); 
              $this-&gt;set_error('password_change_unsuccessful'); 
              return FALSE; 
          } 
  
          $new_password = $this-&gt;ion_auth_model-&gt;forgotten_password_complete($code, $profile-&gt;salt); 
  
          if ($new_password) 
          { 
              $data = array( 
                  'identity'     =&gt; $profile-&gt;{$identity}, 
                  'new_password' =&gt; $new_password 
              ); 
              if(!$this-&gt;config-&gt;item('use_ci_email', 'ion_auth')) 
              { 
                  $this-&gt;set_message('password_change_successful'); 
                  $this-&gt;ion_auth_model-&gt;trigger_events(array('post_password_change', 'password_change_successful')); 
                      return $data; 
              } 
              else 
              { 
                  $message = $this-&gt;load-&gt;view($this-&gt;config-&gt;item('email_templates', 'ion_auth').$this-&gt;config-&gt;item('email_forgot_password_complete', 'ion_auth'), $data, true); 
  
                  $this-&gt;email-&gt;clear(); 
                  $this-&gt;email-&gt;from($this-&gt;config-&gt;item('admin_email', 'ion_auth'), $this-&gt;config-&gt;item('site_title', 'ion_auth')); 
                  $this-&gt;email-&gt;to($profile-&gt;email); 
                  $this-&gt;email-&gt;subject($this-&gt;config-&gt;item('site_title', 'ion_auth') . ' - ' . $this-&gt;lang-&gt;line('email_new_password_subject')); 
                  $this-&gt;email-&gt;message($message); 
  
                  if ($this-&gt;email-&gt;send()) 
                  { 
                      $this-&gt;set_message('password_change_successful'); 
                      $this-&gt;ion_auth_model-&gt;trigger_events(array('post_password_change', 'password_change_successful')); 
                      return TRUE; 
                  } 
                  else 
                  { 
                      $this-&gt;set_error('password_change_unsuccessful'); 
                      $this-&gt;ion_auth_model-&gt;trigger_events(array('post_password_change', 'password_change_unsuccessful')); 
                      return FALSE; 
                  } 
  
              } 
          } 
  
          $this-&gt;ion_auth_model-&gt;trigger_events(array('post_password_change', 'password_change_unsuccessful')); 
          return FALSE; 
      } 
  
      /** 
       * forgotten_password_check 
       * 
       * @return void 
       * @author Michael 
       **/ 
      public function forgotten_password_check($code) 
      { 
          $profile = $this-&gt;where('forgotten_password_code', $code)-&gt;users()-&gt;row(); //pass the code to profile 
  
          if (!is_object($profile)) 
          { 
              $this-&gt;set_error('password_change_unsuccessful'); 
              return FALSE; 
          } 
          else 
          { 
              if ($this-&gt;config-&gt;item('forgot_password_expiration', 'ion_auth') &gt; 0) { 
                  //Make sure it isn't expired 
                  $expiration = $this-&gt;config-&gt;item('forgot_password_expiration', 'ion_auth'); 
                  if (time() - $profile-&gt;forgotten_password_time &gt; $expiration) { 
                      //it has expired 
                      $this-&gt;clear_forgotten_password_code($code); 
                      $this-&gt;set_error('password_change_unsuccessful'); 
                      return FALSE; 
                  } 
              } 
              return $profile; 
          } 
      } 
  
      /** 
       * register 
       * 
       * @return void 
       * @author Mathew 
       **/ 
      public function register($username, $password, $email, $additional_data = array(), $group_ids = array()) //need to test email activation 
      { 
          $this-&gt;ion_auth_model-&gt;trigger_events('pre_account_creation'); 
  
          $email_activation = $this-&gt;config-&gt;item('email_activation', 'ion_auth'); 
  
          if (!$email_activation) 
          { 
              $id = $this-&gt;ion_auth_model-&gt;register($username, $password, $email, $additional_data, $group_ids); 
              if ($id !== FALSE) 
              { 
                  $this-&gt;set_message('account_creation_successful'); 
                  $this-&gt;ion_auth_model-&gt;trigger_events(array('post_account_creation', 'post_account_creation_successful')); 
                  return $id; 
              } 
              else 
              { 
                  $this-&gt;set_error('account_creation_unsuccessful'); 
                  $this-&gt;ion_auth_model-&gt;trigger_events(array('post_account_creation', 'post_account_creation_unsuccessful')); 
                  return FALSE; 
              } 
          } 
          else 
          { 
              $id = $this-&gt;ion_auth_model-&gt;register($username, $password, $email, $additional_data, $group_ids); 
  
              if (!$id) 
              { 
                  $this-&gt;set_error('account_creation_unsuccessful'); 
                  return FALSE; 
              } 
  
              $deactivate = $this-&gt;ion_auth_model-&gt;deactivate($id); 
  
              if (!$deactivate) 
              { 
                  $this-&gt;set_error('deactivate_unsuccessful'); 
                  $this-&gt;ion_auth_model-&gt;trigger_events(array('post_account_creation', 'post_account_creation_unsuccessful')); 
                  return FALSE; 
              } 
  
              $activation_code = $this-&gt;ion_auth_model-&gt;activation_code; 
              $identity        = $this-&gt;config-&gt;item('identity', 'ion_auth'); 
              $user            = $this-&gt;ion_auth_model-&gt;user($id)-&gt;row(); 
  
              $data = array( 
                  'identity'   =&gt; $user-&gt;{$identity}, 
                  'id'         =&gt; $user-&gt;id, 
                  'email'      =&gt; $email, 
                  'activation' =&gt; $activation_code, 
              ); 
              if(!$this-&gt;config-&gt;item('use_ci_email', 'ion_auth')) 
              { 
                  $this-&gt;ion_auth_model-&gt;trigger_events(array('post_account_creation', 'post_account_creation_successful', 'activation_email_successful')); 
                  $this-&gt;set_message('activation_email_successful'); 
                      return $data; 
              } 
              else 
              { 
                  $message = $this-&gt;load-&gt;view($this-&gt;config-&gt;item('email_templates', 'ion_auth').$this-&gt;config-&gt;item('email_activate', 'ion_auth'), $data, true); 
  
                  $this-&gt;email-&gt;clear(); 
                  $this-&gt;email-&gt;from($this-&gt;config-&gt;item('admin_email', 'ion_auth'), $this-&gt;config-&gt;item('site_title', 'ion_auth')); 
                  $this-&gt;email-&gt;to($email); 
                  $this-&gt;email-&gt;subject($this-&gt;config-&gt;item('site_title', 'ion_auth') . ' - ' . $this-&gt;lang-&gt;line('email_activation_subject')); 
                  $this-&gt;email-&gt;message($message); 
  
                  if ($this-&gt;email-&gt;send() == TRUE) 
                  { 
                      $this-&gt;ion_auth_model-&gt;trigger_events(array('post_account_creation', 'post_account_creation_successful', 'activation_email_successful')); 
                      $this-&gt;set_message('activation_email_successful'); 
                      return $id; 
                  } 
  
              } 
  
              $this-&gt;ion_auth_model-&gt;trigger_events(array('post_account_creation', 'post_account_creation_unsuccessful', 'activation_email_unsuccessful')); 
              $this-&gt;set_error('activation_email_unsuccessful'); 
              return FALSE; 
          } 
      } 
  
      /** 
       * logout 
       * 
       * @return void 
       * @author Mathew 
       **/ 
      public function logout() 
      { 
          $this-&gt;ion_auth_model-&gt;trigger_events('logout'); 
  
          $identity = $this-&gt;config-&gt;item('identity', 'ion_auth'); 
                  $this-&gt;session-&gt;unset_userdata( array($identity =&gt; '', 'id' =&gt; '', 'user_id' =&gt; '') ); 
  
          //delete the remember me cookies if they exist 
          if (get_cookie($this-&gt;config-&gt;item('identity_cookie_name', 'ion_auth'))) 
          { 
              delete_cookie($this-&gt;config-&gt;item('identity_cookie_name', 'ion_auth')); 
          } 
          if (get_cookie($this-&gt;config-&gt;item('remember_cookie_name', 'ion_auth'))) 
          { 
              delete_cookie($this-&gt;config-&gt;item('remember_cookie_name', 'ion_auth')); 
          } 
  
          //Destroy the session 
          $this-&gt;session-&gt;sess_destroy(); 
  
          //Recreate the session 
          if (substr(CI_VERSION, 0, 1) == '2') 
          { 
              $this-&gt;session-&gt;sess_create(); 
          } 
          else 
          { 
              $this-&gt;session-&gt;sess_regenerate(TRUE); 
          } 
  
          $this-&gt;set_message('logout_successful'); 
          return TRUE; 
      } 
  
      /** 
       * logged_in 
       * 
       * @return bool 
       * @author Mathew 
       **/ 
      public function logged_in() 
      { 
          $this-&gt;ion_auth_model-&gt;trigger_events('logged_in'); 
  
          return (bool) $this-&gt;session-&gt;userdata('identity'); 
      } 
  
      /** 
       * logged_in 
       * 
       * @return integer 
       * @author jrmadsen67 
       **/ 
      public function get_user_id() 
      { 
          $user_id = $this-&gt;session-&gt;userdata('user_id'); 
          if (!empty($user_id)) 
          { 
              return $user_id; 
          } 
          return null; 
      } 
  
  
      /** 
       * is_admin 
       * 
       * @return bool 
       * @author Ben Edmunds 
       **/ 
      public function is_admin($id=false) 
      { 
          $this-&gt;ion_auth_model-&gt;trigger_events('is_admin'); 
  
          $admin_group = $this-&gt;config-&gt;item('admin_group', 'ion_auth'); 
  
          return $this-&gt;in_group($admin_group, $id); 
      } 
  
      /** 
       * in_group 
       * 
       * @param mixed group(s) to check 
       * @param bool user id 
       * @param bool check if all groups is present, or any of the groups 
       * 
       * @return bool 
       * @author Phil Sturgeon 
       **/ 
      public function in_group($check_group, $id=false, $check_all = false) 
      { 
          $this-&gt;ion_auth_model-&gt;trigger_events('in_group'); 
  
          $id || $id = $this-&gt;session-&gt;userdata('user_id'); 
  
          if (!is_array($check_group)) 
          { 
              $check_group = array($check_group); 
          } 
  
          if (isset($this-&gt;_cache_user_in_group[$id])) 
          { 
              $groups_array = $this-&gt;_cache_user_in_group[$id]; 
          } 
          else 
          { 
              $users_groups = $this-&gt;ion_auth_model-&gt;get_users_groups($id)-&gt;result(); 
              $groups_array = array(); 
              foreach ($users_groups as $group) 
              { 
                  $groups_array[$group-&gt;id] = $group-&gt;name; 
              } 
              $this-&gt;_cache_user_in_group[$id] = $groups_array; 
          } 
          foreach ($check_group as $key =&gt; $value) 
          { 
              $groups = (is_string($value)) ? $groups_array : array_keys($groups_array); 
  
              /** 
               * if !all (default), in_array 
               * if all, !in_array 
               */ 
              if (in_array($value, $groups) xor $check_all) 
              { 
                  /** 
                   * if !all (default), true 
                   * if all, false 
                   */ 
                  return !$check_all; 
              } 
          } 
          /** 
           * if !all (default), false 
           * if all, true 
           */ 
          return $check_all; 
      } 
  }
  </code></pre>