title: Ion Auth & Codeigniter: Looping redirect when new user login
body: <p>I am a frequent user of Codeigniter and it has come to the point where i've had to start looking at a library for login/forgot password so i decided to use Ion Auth.</p>
  
  <p>I set this up - works fine, tried the admin account that is already set up with it and it's fine.</p>
  
  <p>Now when i login as the admin and then create a new user, the data is added to the database and the page redirects from "create-user" to the welcome page. But if i logout and login with these new details, the page goes blank and the reload bar goes crazy! The url bar looks like it goes to the welcome page if that makes sense but nothing loads.</p>
  
  <p>I've also checked my console on firebug and the php log error and nothing at all.</p>
  
  <p>I've checked my database and when the user has been added, the password has been hashed but in the salt column it is classed as NULL whereas the default account already set up has a hash code? - could this be something to do with it?</p>
  
  <p>EDIT: I've now altered the code but this still didn't worked when it wasn't touched so only edits in code are removal of tables and in the auth controller the functions are login, create_user and logout.</p>
  
  <p>And when the admin@admin.com user logs in it loads the page fine just other"new" accounts..</p>
  
  <p>Thanks!</p>
  
  <pre><code>    //log the user in
      function login() {
  
          $this-&gt;data['title'] = "Login";
  
          $this-&gt;form_validation-&gt;set_rules('identity', 'Identity', 'required');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required');
  
          if ($this-&gt;form_validation-&gt;run() == true) {
  
              //check for "remember me"
              $remember = (bool) $this-&gt;input-&gt;post('remember');
  
              if ($this-&gt;ion_auth-&gt;login($this-&gt;input-&gt;post('identity'), $this-&gt;input-&gt;post('password'), $remember)) {
  
                  //if the login is successful
                  //redirect them back to the home page
                  $this-&gt;session-&gt;set_flashdata('message', $this-&gt;ion_auth-&gt;messages());
                  redirect('/', 'refresh');
              }else{
                  //if the login was un-successful
                  //redirect them back to the login page
                  $this-&gt;session-&gt;set_flashdata('message', $this-&gt;ion_auth-&gt;errors());
                  redirect('auth/login', 'refresh');
              }
          }else{
  
              //the user is not logging in so display the login page
              $this-&gt;data['message'] = (validation_errors()) ? validation_errors() : $this-&gt;session-&gt;flashdata('message');
  
              $this-&gt;data['identity'] = array('name' =&gt; 'identity',
                  'id' =&gt; 'identity',
                  'type' =&gt; 'text',
                  'value' =&gt; $this-&gt;form_validation-&gt;set_value('identity'),
              );
              $this-&gt;data['password'] = array('name' =&gt; 'password',
                  'id' =&gt; 'password',
                  'type' =&gt; 'password',
              );
  
              $this-&gt;_render_page('auth/login', $this-&gt;data);
          }
      }
  
  
      //log the user out
      function logout() {
  
          $this-&gt;data['title'] = "Logout";
  
          $logout = $this-&gt;ion_auth-&gt;logout();
  
          $this-&gt;session-&gt;set_flashdata('message', $this-&gt;ion_auth-&gt;messages());
          redirect('auth/login', 'refresh');
      }
  
  
  
      //create a new user
      function create_user() {
  
          $this-&gt;data['title'] = "Create User";
  
          $this-&gt;form_validation-&gt;set_rules('first_name', 'First Name', 'required|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('last_name', 'Last Name', 'required|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('email', 'Email Address', 'required|valid_email');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required|min_length[' . $this-&gt;config-&gt;item('min_password_length', 'ion_auth') . ']|max_length[' . $this-&gt;config-&gt;item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
          $this-&gt;form_validation-&gt;set_rules('password_confirm', 'Password Confirmation', 'required');
  
          if ($this-&gt;form_validation-&gt;run() == true) {
  
              $username = strtolower($this-&gt;input-&gt;post('first_name')) . ' ' . strtolower($this-&gt;input-&gt;post('last_name'));
              $email    = $this-&gt;input-&gt;post('email');
              $password = $this-&gt;input-&gt;post('password');
  
              $additional_data = array(
                  'first_name' =&gt; $this-&gt;input-&gt;post('first_name'),
                  'last_name'  =&gt; $this-&gt;input-&gt;post('last_name')
  
              );
          }
          if ($this-&gt;form_validation-&gt;run() == true &amp;&amp; $this-&gt;ion_auth-&gt;register($username, $password, $email, $additional_data)) {
              //check to see if we are creating the user
              //redirect them back to the admin page
              $this-&gt;session-&gt;set_flashdata('message', $this-&gt;ion_auth-&gt;messages());
              redirect("auth/login", 'refresh');
          }else{
              //display the create user form
              //set the flash data error message if there is one
              $this-&gt;data['message'] = (validation_errors() ? validation_errors() : ($this-&gt;ion_auth-&gt;errors() ? $this-&gt;ion_auth-&gt;errors() : $this-&gt;session-&gt;flashdata('message')));
  
              $this-&gt;data['first_name'] = array(
                  'name'  =&gt; 'first_name',
                  'id'    =&gt; 'first_name',
                  'type'  =&gt; 'text',
                  'value' =&gt; $this-&gt;form_validation-&gt;set_value('first_name'),
              );
              $this-&gt;data['last_name'] = array(
                  'name'  =&gt; 'last_name',
                  'id'    =&gt; 'last_name',
                  'type'  =&gt; 'text',
                  'value' =&gt; $this-&gt;form_validation-&gt;set_value('last_name'),
              );
              $this-&gt;data['email'] = array(
                  'name'  =&gt; 'email',
                  'id'    =&gt; 'email',
                  'type'  =&gt; 'text',
                  'value' =&gt; $this-&gt;form_validation-&gt;set_value('email'),
              );
              $this-&gt;data['password'] = array(
                  'name'  =&gt; 'password',
                  'id'    =&gt; 'password',
                  'type'  =&gt; 'password',
                  'value' =&gt; $this-&gt;form_validation-&gt;set_value('password'),
              );
              $this-&gt;data['password_confirm'] = array(
                  'name'  =&gt; 'password_confirm',
                  'id'    =&gt; 'password_confirm',
                  'type'  =&gt; 'password',
                  'value' =&gt; $this-&gt;form_validation-&gt;set_value('password_confirm'),
              );
  
              $this-&gt;_render_page('auth/create_user', $this-&gt;data);
          }
      }
  
      function _render_page($view, $data=null, $render=false) {
  
          $this-&gt;viewdata = (empty($data)) ? $this-&gt;data: $data;
  
          $view_html = $this-&gt;load-&gt;view($view, $this-&gt;viewdata, $render);
  
          if (!$render) return $view_html;
      }
  
  }
  </code></pre>
  
  <p><strong>WELCOME PAGE CONTROLLER</strong></p>
  
  <pre><code>class Welcome extends CI_Controller {
  
      function __construct() {
  
          parent::__construct();
          $this-&gt;load-&gt;library('ion_auth');
          $this-&gt;load-&gt;library('session');
          $this-&gt;load-&gt;library('form_validation');
          $this-&gt;load-&gt;helper('url');
      }
  
  
          public function index() {
  
          if (!$this-&gt;ion_auth-&gt;logged_in()) {
              redirect('auth/login', 'refresh');
  
          }elseif (!$this-&gt;ion_auth-&gt;is_admin()) {
              redirect('/', 'refresh');
          }else{
              $this-&gt;data['message'] = (validation_errors()) ? validation_errors() : $this-&gt;session-&gt;flashdata('message');
              $this-&gt;_render_page('auth/welcome', $this-&gt;data);
          }
      }
  }
  </code></pre>
  
  <p>RESOLVED: This was a bug with Google Chrome which i've had to update the system and the brwser. Also for storing the SALT i changed some settings in my ion_auth config file</p>