1
votes

The application has been working perfectly for over two years, only for me not to be able to log into the web app. I discovered that $this->session->set_userdata() is not working. I input my credentials and i get redirected back to the login page. I tried to used an statement on the set_userdata() and found out that it is not working. My code is shown below

/* Autoload.php*/
$autoload['libraries'] = array('database', 'email', 'session');
/* Config.php */
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = BASEPATH.'sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

/* Login Controller */
public function verify_login(){
        $this->load->library('session');
        $pass = $this->input->post('password');
        $username = $this->input->post('username');
        $action = 'Login';
        if($this->admodel->Check_Login_In_DB($username,$pass)){
            $sess_array = array();
            $sess_array = array(
            'uid' =>  $this->admodel->getUidByUsername($username),
            'username' => $username
       );
       $this->session->set_userdata($sess_array);
       $this->admodel->insertLog($action,$this->admodel->getUidByUsername($username));
       redirect(base_url(), 'refresh');
        }else{
        $this->session->set_flashdata('msg','<div style="color:#b94a48;
        background-color:#f2dede;border-color:#eed3d7;height:auto;padding:5px;border-radius:3px;margin-bottom:7px;
        clear:both">The Email and Password Combination is not found in the database,Check Properly and try again !!!</div>');
            redirect(base_url().'login','refresh');
        }

    }

/* Homepage */
public function index(){

        if(!$this->session->userdata('uid')){

            $this->session->set_flashdata('msg','<div style="color: #b94a48;background-color:

            #f2dede;border-color: #eed3d7;height:auto;padding:5px;border-radius:3px;clear:both;margin-bottom:10px">

            You need to signin to continue !!!</div>');

            redirect(base_url().'login','refresh');

        }
1
Is $this->admodel->Check_Login_In_DB returning true? Otherwise $sess_array will be undefined. Everytime the use insert wrong credentials It will generate a warning. What's in your logs? - Felippe Duarte
I know this is not the subject at hand, but consider using something like Ion_auth for authentication on your codeigniter projects. - marcogmonteiro
@marcogmonteiro care to elaborate why? Ion auth works fine, but it's not the only way - Javier Larroulet
@JavierLarroulet sure its not the only way to do things, but its the more secure way. There's also the other argument to be made where if you work with a team and not alone or need to include more people in the project in the future, its well documented and easier for your team to debug, make changes or even build new features. - marcogmonteiro

1 Answers

1
votes

Please change the session syntax like that.

$this->session->set_userdata('user_session',$sess_array);

It will work.