codeigniter:如何检查用户名和密码
Posted
技术标签:
【中文标题】codeigniter:如何检查用户名和密码【英文标题】:codeigniter:how to check user name and password 【发布时间】:2016-09-24 05:03:35 【问题描述】:如果登录失败,那么如何重定向相同的登录页面并显示错误的用户名 $('#login_form').submit(函数 (e) e.preventDefault(); var uname = $('#uname').val(); var uppassword = $('#uppassword').val(); if (uname == "" || uppassword == "") $('#errmessage').show().html('所有字段都是必需的'); 别的 $('#errmessage').html("").hide(); $.ajax( 类型:“发布”, url: "User_controller/login_auth/", 数据类型:'json', 数据:uname:uname,upassword:upassword, 成功:函数(数据) $('#successmessage').fadeIn().html(数据), window.location.replace("/User_controller/profile"); ); ); 检查登录权限,如果成功则重定向到个人资料页面
public function login_autho()
$data = array(
'uname' => $this->input->post('uname'),
'upassword' => $this->input->post('upassword')
);
$result = $this->login_model->login_user($data);
if ($result == TRUE)
$this->session->set_flashdata('success', 'Success Login');
$this->load->view('user/success');
// echo 'su';
else
//$this->session->set_flashdata('error', 'Invalid Username or Password');
//echo 'invalid user';
// echo json_encode(false);
public function profile()
$this->load->view('header');
$this->load->view('user/success');
【问题讨论】:
【参考方案1】:简单易写
$uname = $this->input->post('uname');
$upassword = $this->input->post('upassword');
将这些变量传递给模型函数
$this->Model->login($uname,$upassword); // Login method you have to create
if($query->count() ==1 )
echo 'login';
else
echo "failed";
然后签入数据库
$query = $this->db->query('SELECT * FROM 'your_table_name' WHERE 'uname'= $uname AND 'password' = $uppassword '); // 根据您的要求查询修改
return $query->count();
【讨论】:
【参考方案2】:控制器
$uname = $this->input->post('uname');
$upassword = $this->input->post('upassword');
$result= $this->Model->login($uname,$upassword); // Login method you have to create
if($result=='login')
header('location:dashbord.php');
else
header('location:index.php?error=1');
模态
public function login($uname,$upassword)
$query = $this->db->query('SELECT * FROM 'your_table_name' WHERE uname='. $uname. ' AND password='. $upassword); // Query modify as per ur requirement
if(count($query) ==1 )
echo 'login';
else
echo "failed";
【讨论】:
以上是关于codeigniter:如何检查用户名和密码的主要内容,如果未能解决你的问题,请参考以下文章