[英]CodeIgniter - Login is not working
I'm currently working with admin page. 我目前正在使用管理页面。 I logged in my username and password correctly but it says "404 Page Not Found - The page you requested was not found." 我正确登录了用户名和密码,但显示“ 404页面未找到-未找到您请求的页面”。
This is the controller: 这是控制器:
public function login()
{
$header = array("title" => "Welcome - ");
$this->load->view('includes/header', $header);
$this->load->view('accounts/login');
$this->load->view('includes/footer');
}
public function login_submit()
{
$data = array(
'username' => $this->input->post('username'),
'password' => sha1($this->input->post('password'))
);
$this->form_validation->set_rules('username', 'Username', 'required|is_unique[accounts.username]|min_length[6]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]');
$accountDetails = $this->accounts_model->fetch('accounts', $data);
if (!$accountDetails) {
echo "<script>alert('Account does not exist!'); window.location.href = '".base_url()."accounts/login';</script>";
} else {
$accountDetails = $accountDetails[0];
if ($accountDetails->status == 1) {
$header = array("title" => "Account - ");
$this->load->view('includes/header', $header);
$this->load->view('admin/home', $accountDetails);
$this->load->view('includes/footer');
} else {
echo "<script>alert('You account is blocked!'); window.location.href = '".base_url()."accounts/login';</script>";
}
}
}
I hope this code will help you..Works fine 希望这段代码对您有所帮助。
plz set your form like this: 请设置您的表单,如下所示:
<form action='<?php echo base_url();?>index.php/accounts/login_submit' method='post' name='process'>
accounts Controller 会计主管
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Author: Pedram shabani
* Description: accounts controller class
*/
class accounts extends CI_Controller{
function __construct(){
parent::__construct();
}
public function login($msg = NULL)
{
$data['msg'] = $msg;
$this->load->helper('url');
$header = array("title" => "Welcome - ");
$this->load->view('includes/header', $header);
$this->load->view('accounts/login',$data);
$this->load->view('includes/footer');
}
public function login_submit()
{
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
$data = array(
'username' => $this->input->post('username'),
'password' => sha1($this->input->post('password'))
);
$this->load->model('accounts_model');
$accountDetails = $this->accounts_model->fetch($data);
if(! $accountDetails){
// If user did not validate, then show them login page again
$msg = '<font color=red>Invalid username and/or password.</font><br />';
$this->login($msg);
}else{
$this->load->helper('url');
$header = array("title" => "Welcome - ");
$this->load->view('includes/header', $header);
$this->load->view('accounts/login',$data);
$this->load->view('includes/footer');
}
}
}
?>
accounts_model account_model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class accounts_model extends CI_Model{
function __construct(){
parent::__construct();
}
public function fetch ($data){
// die(var_dump($data));
$this->db->select('*');
$this->db->where('username', $data['username']);
$this->db->where('password', $data['password']);
$query = $this->db->get('users');
$num = $query->num_rows();
if($query->num_rows == 1)
{
$row = $query->row();
$data = array(
'userid' => $row->userid,
'fname' => $row->fname,
'lname' => $row->lname,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
return false;
}
}
?>
and at the end.plz set default controller 并在最后.plz设置默认控制器
$route['default_controller'] = 'login';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.