I m trying to set Session in codeigniter. when a person try to login with email id and password.
1st) using email id find his/her role. then return that result in session and redirect to respective link. the code I typed below. Could you please solve this issue?
Controller
public function login_validation() {
$this -> load -> library('form_validation');
$this -> form_validation -> set_rules('email', 'Email', 'required|trim');
$this -> form_validation -> set_rules('password', 'Password', 'required ');
if ($this -> form_validation -> run()) {
$this -> load -> model('model_database');
$sessiondata['var_userrole'] = $this -> model_database -> login_session();
$this -> session -> set_userdata($sessiondata);
if ($var_userrole == admin) {
redirect('welcome/admin');
} else if ($var_userrole == staff) {
redirect('welcome/staff');
} else if ($var_userrole == student) {
redirect('welcome/student');
} else {
redirect('welcome/login');
}
Model
public function login_session() {
$email = $this -> input -> post('email');
$login_id = $this -> db -> query("SELECT var_userrole FROM tbl_login where var_email = '" . $email . "'");
return $login_id -> row_array();
}