Codeigniter Inputting session data from model for a simple authentication system

Posted by user1616244 on Stack Overflow See other posts from Stack Overflow or by user1616244
Published on 2012-09-08T15:36:04Z Indexed on 2012/09/08 15:37 UTC
Read the original article Hit count: 196

Filed under:
|
|
|

Trying to put together a simple login authentication. Been at this for quite sometime, and I can't find where I'm going wrong. Pretty new to Codeigniter and OOP PHP. I know there are authentication libraries out there, but I'm not interested in using those.

Model:

 function login($username, $password){

    if ($this->db->table_exists($username)){
    $this->db->where('username', $username);
    $this->db->where('password', $password);
    $query = $this->db->get($username); 

        if($query->num_rows >= 1)
        {
        return true;
        $data = array(
            'username' => $this->input->post('username'),
            'login' => true
            );
            $this->session->set_userdata($data);

        } 
    }  
    }

Controller

function __construct(){
    parent::__construct();
    $this->logincheck();
}
public function logincheck(){
    if ($this->session->userdata('login')){
        redirect('/members');
        }
    }

If I just echo from the controller: $this->session->all_userdata(); I get an empty array. So the problem seems to be that the $data array in the model isn't being stored in the session.

© Stack Overflow or respective owner

Related posts about php

Related posts about oop