I have been an avid reader of stackoverflow for a long period of time, and now its my turn to ask a question.
I followed http://net.tutsplus.com/tutorials/php/easy-authentication-with-codeigniter/ tutorial and have managed to get it to work flawlessly for my self, however I need to expand the system ever so slightly. I need to be able to after the user has been verified to pull additional row fields of the authenticated person and store in session variables, for use in other controllers for sending information back to the database.
For instance I want to have in a sessional variable $f_name, and I need their $username. I have looked high and low and have found answers but they have only confused me.
My Model:
class admin_model extends CI_Model {
function __construct( )
{
}
public function verify_user($user_id, $password)
{
$q = $this->db->where('user_id', $user_id)
->where('password', sha1($password))->limit(1)->get('users');
if ( $q->num_rows > 0 ){
return $q->row();
}
return false;
}
}
My Controller:
class admin extends CI_Controller {
function __construct()
{
parent:: __construct();
session_start();
}
public function index()
{
if ( isset($_SESSION['user_id'])){
redirect('welcome');
}
$this->load->library('form_validation');
$this->form_validation->set_rules('user_id', 'User ID', 'required|min_length[8]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[4]');
if ($this->form_validation->run() !==false){
$this->load->model('admin_model');
$res = $this
->admin_model
->verify_user(
$this->input->post('user_id'),
$this->input->post('password')
);
if ($res !== false) {
$_SESSION['user_id'] = $this->input->post('user_id');
redirect ('welcome');
}
}
$this->load->view('login_view');
}
public function logout(){
session_destroy();
redirect ('admin');
}
}
Thanks again guys and I look forward to your answers\suggestions