在CodeIgniter中设置会话错误
我试图在codeigniter中设置会话。当某人尝试使用电子邮件id和密码登录时 1)使用电子邮件id查找他/她的角色。然后在会话中返回该结果并重定向到相应的链接。我在下面键入的代码。你能解决这个问题吗 控制器在CodeIgniter中设置会话错误,codeigniter,Codeigniter,我试图在codeigniter中设置会话。当某人尝试使用电子邮件id和密码登录时 1)使用电子邮件id查找他/她的角色。然后在会话中返回该结果并重定向到相应的链接。我在下面键入的代码。你能解决这个问题吗 控制器 public function login_validation() { $this -> load -> library('form_validation'); $this -> form_validation -> set_ru
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');
}
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');
$var_userrole = $this -> model_database -> login_session();// was undefined
$sessiondata['var_userrole'] = $var_userrole
$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');
}
型号
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();
}
public function login_session() {
$email = $this -> input -> post('email');
$login_id = $this -> db -> query("SELECT var_userrole FROM tbl_login where var_email = '" . $email . "'");
//$row = $login_id -> row() // as object return $row->var_userrole;
$row = $login_id -> row_array();
return $row['var_userrole']
}
首先,在您签入if语句的任何地方都没有定义$var_userrole 控制器
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');
}
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');
$var_userrole = $this -> model_database -> login_session();// was undefined
$sessiondata['var_userrole'] = $var_userrole
$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');
}
型号
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();
}
public function login_session() {
$email = $this -> input -> post('email');
$login_id = $this -> db -> query("SELECT var_userrole FROM tbl_login where var_email = '" . $email . "'");
//$row = $login_id -> row() // as object return $row->var_userrole;
$row = $login_id -> row_array();
return $row['var_userrole']
}
如果在此之前您正在为auth开发新的东西,请检查CI中的一些auth系统,如ion_auth拥有您可以管理的组,并检查用户属于哪个组以及问题是什么??问题到底是什么@bipen和Distinct:我是CodeIgniter的初学者。在查看用户指南后,无法设置会话。没有错误,但不工作!我想知道我对控制器会话代码所做的操作是否正确?非常感谢你的时间。如果代码不正确,请指出正确的方法。我们无法帮助您,因为我们看不到任何问题,代码到底出了什么问题?