Php Codeigniter 3登录问题直接进入页面,无需验证
我有一个问题,每次我点击登录它只是带我到我的页面,它似乎没有检查,看看是否输入用户名或密码。我不确定问题出在哪里,我将行Php Codeigniter 3登录问题直接进入页面,无需验证,php,html,codeigniter-3,Php,Html,Codeigniter 3,我有一个问题,每次我点击登录它只是带我到我的页面,它似乎没有检查,看看是否输入用户名或密码。我不确定问题出在哪里,我将行if($this->form\u validation->run()==FALSE)更改为true,然后在输入正确密码时,我被重定向回登录。我想我只是错过了一些简单的东西。如果有人有想法,任何方向都会有帮助,同时我会不断地找出答案 控制器 Verifylogin.phpcontroller <?php if ( ! defined('BASEPATH')) exit('N
if($this->form\u validation->run()==FALSE)
更改为true,然后在输入正确密码时,我被重定向回登录。我想我只是错过了一些简单的东西。如果有人有想法,任何方向都会有帮助,同时我会不断地找出答案
控制器
Verifylogin.phpcontroller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class VerifyLogin extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}
function index()
{
//This method will have the credentials validation
$this->load->library('form_validation');
if($this->form_validation->run() == false)
{
//Field validation failed. User redirected to login page
$this->load->view('person_view');
}
else
{
//Go to private area
redirect('Person', 'refresh');
}
}
public function check_database() {
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE) {
$this->load->view('login_view.php');
} else {
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$result = $this->admin_database->login($data);
if($result == TRUE){
$sess_array = array(
'username' => $this->input->post('username')
);
}
}
}
}
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Person extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('person_model','callin_list');
}
public function index()
{
if($this->session->userdata('logged_in'))
{
$this->load->view('person_view');
}else
{
//If no session, redirect to login page
redirect('login', 'refresh');
}
}
public function ajax_list()
{
$list = $this->callin_list->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $callin_list) {
$no++;
$row = array();
$row[] = $callin_list->Date_Scheduled;
$row[] = $callin_list->Employee_Name;
$row[] = $callin_list->Employee_Number;
$row[] = $callin_list->Time_Reported;
$row[] = $callin_list->Reason;
$row[] = $callin_list->Scheduled_Area;
$row[] = $callin_list->Contact;
$row[] = $callin_list->Comments;
//add html for action
$row[] = '<a class="btn btn-sm btn-primary" href="javascript:void()" title="Edit" onclick="edit_person('."'".$callin_list->id."'".')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn btn-sm btn-danger" href="javascript:void()" title="Hapus" onclick="delete_person('."'".$callin_list->id."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->callin_list->count_all(),
"recordsFiltered" => $this->callin_list->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
public function ajax_edit($id)
{
$data = $this->callin_list->get_by_id($id);
echo json_encode($data);
}
public function ajax_add()
{
$this->_validate();
$data = array(
'Date_Scheduled' => $this->input->post('Date_Scheduled'),
'Employee_Name' => $this->input->post('Employee_Name'),
'Employee_Number' => $this->input->post('Employee_Number'),
'Time_Reported' => $this->input->post('Time_Reported'),
'Reason' => $this->input->post('Reason'),
'Scheduled_Area' => $this->input->post('Scheduled_Area'),
'Contact' => $this->input->post('Contact'),
'Comments' => $this->input->post('Comments'),
);
$insert = $this->callin_list->save($data);
echo json_encode(array("status" => TRUE));
}
public function ajax_update()
{
$this->_validate();
$data = array(
'Date_Scheduled' => $this->input->post('Date_Scheduled'),
'Employee_Name' => $this->input->post('Employee_Name'),
'Employee_Number' => $this->input->post('Employee_Number'),
'Time_Reported' => $this->input->post('Time_Reported'),
'Reason' => $this->input->post('Reason'),
'Scheduled_Area' => $this->input->post('Scheduled_Area'),
'Contact' => $this->input->post('Contact'),
'Comments' => $this->input->post('Comments'),
);
$this->callin_list->update(array('id' => $this->input->post('id')), $data);
echo json_encode(array("status" => TRUE));
}
public function ajax_delete($id)
{
$this->callin_list->delete_by_id($id);
echo json_encode(array("status" => TRUE));
}
//validation section were user must enter data in all fields
private function _validate()
{
$data = array();
$data['error_string'] = array();
$data['inputerror'] = array();
$data['status'] = TRUE;
if($this->input->post('Date_Scheduled') == '')
{
$data['inputerror'][] = 'Date_Scheduled';
$data['error_string'][] = 'Date_Scheduled is required';
$data['status'] = FALSE;
}
if($this->input->post('Employee_Name') == '')
{
$data['inputerror'][] = 'Employee_Name';
$data['error_string'][] = 'Employee_Name is required';
$data['status'] = FALSE;
}
if($this->input->post('Employee_Number') == '')
{
$data['inputerror'][] = 'Employee_Number';
$data['error_string'][] = 'Employee_Number is required';
$data['status'] = FALSE;
}
if($this->input->post('Time_Reported') == '')
{
$data['inputerror'][] = 'Time_Reported';
$data['error_string'][] = 'Time_Reported is required';
$data['status'] = FALSE;
}
if($this->input->post('Reason') == '')
{
$data['inputerror'][] = 'Reason';
$data['error_string'][] = 'Reason is required';
$data['status'] = FALSE;
}
if($this->input->post('Scheduled_Area') == '')
{
$data['inputerror'][] = 'Scheduled_Area';
$data['error_string'][] = 'Scheduled_Area is required';
$data['status'] = FALSE;
}
if($this->input->post('Contact') == '')
{
$data['inputerror'][] = 'Contact';
$data['error_string'][] = 'contact is required';
$data['status'] = FALSE;
}
if($this->input->post('Comments') == '')
{
$data['inputerror'][] = 'Comments';
$data['error_string'][] = 'Comments is required';
$data['status'] = FALSE;
}
if($data['status'] === FALSE)
{
echo json_encode($data);
exit();
}
}
}
您正在将数据发送到verifylogin/index,并且随时都在加载规则以进行检查和验证,这两个规则都没有从数据库中进行检查。这就是问题所在。使用$this->form\u validation->run()==FALSE
代替,使用3个=
符号 因此,我需要使用checkdatabase来代替verifylogin/checkdatabaseYes,您还应该将逻辑更改为if(语句){//Dosomethinwhen is true}else{//Dosomethinwhen is false}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Author: Jorge Torres
* Description: Login model class
*/
class Login_model extends CI_Model{
function __construct(){
parent::__construct();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
// Prep the query
$this->db->where('username', $username);
$this->db->where('password', $password);
// Run the query
$query = $this->db->get('users');
// Let's check if there are any results
if($query->num_rows() == 1)
{
// If there is a user, then create session data
$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;
}
// If the previous process did not validate
// then return false.
return false;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login Form</title>
<style type="text/css">
.content{
margin-left: 400px;
margin-top: 300px;
}
.btn{
width:242px;
height: 50px;
}
#label{
font-size: 24px;
font-weight: normal;
}
</style>
<link href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css')?>" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="content">
<h1>DC399 Callin Login Page</h1>
<?php echo validation_errors(); ?>
<?php echo form_open('verifylogin'); ?>
<label id="label"for="username">Username:</label><br>
<input type="text" size="20" id="username"style="width: 239px; height: 40px; margin-right: 20px;"name="username"/>
<br/>
<label id="label" for="password">Password:</label><br>
<input type="password" size="20" id="passowrd" style="width: 239px; height: 40px; margin-right: 20px;"name="password"/>
<br/><br>
<input class="btn btn-success" type="submit" value="Login"/>
</form>
</div>
</div>
<script src="<?php echo base_url('assets/jquery/jquery-2.1.4.min.js')?>"></script>
<script src="<?php echo base_url('assets/bootstrap/js/bootstrap.min.js')?>"></script>
</body>
</html>