您请求的操作是不允许的.点火枪 [英] The action you have requested is not allowed. Codeigniter
问题描述
我正在尝试在codeigniter中创建一个简单的登录系统.当我单击按钮登录名时,出现错误:
I'm trying to make a simple login system in codeigniter. When I click on my button login I get an error:
不允许您执行请求的操作.
打开控制台时,我看到以下内容:
When I open my console I see this:
POST
http://localhost/PHP/PROJECT/CodeIgniter/
403(禁止)
POST
http://localhost/PHP/PROJECT/CodeIgniter/
403 (Forbidden)
这是我的观点:
<body>
<h1>LOG IN!</h1>
<form action="" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" >
<label for="password">Password</label>
<input type="password" id="password" name="password" >
<br>
<button id="btn_login" name="btn_login" >LOG IN!</button>
</form>
<div class="errors" ><?php echo validation_errors(); ?></div>
</body>
这是我的模特
<?php
class User_model extends CI_Model {
public $m_sUsername;
public $m_sPassword;
public $m_sEmail;
public $m_sPicture;
function __construct()
{
parent::__construct();
}
function get_user($username, $password)
{
$this->db->select("username","password");
$this->db->from(user);
$this->db->where('username',$username);
$this->db->where('password',$password);
$this->db->limit(1);
$query = $this->db->get();
return $query->num_rows();
}
}
这是我的控制器:
<?php
class Login extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->helper('html');
$this->load->database();
$this->load->library('form_validation');
$this->load->model("User_model", "", true);
}
public function index()
{
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$username = $this->input->post("username");
$password = $this->input->post("password");
$this->form_validation->set_rules("username", "Username", "trim|required");
$this->form_validation->set_rules("password", "Password", "trim|required");
if ($this->form_validation->run() == FALSE) {
//validation fails
echo "Vul alle velden in";
} else {
//validation succeeds
if ($this->input->post('btn_login') == "Login") {
//check if username and password is correct
$usr_result = $this->User_model->get_user($username, $password);
if ($usr_result > 0) { //active user record is present
echo 'Ingelogd!';
} else {
echo "Wrong!";
}
}
}
}
$this->load->view("admin/login_view.php");
}
}
如何解决此问题?
推荐答案
检查您的 config.php
如果是
Check your config.php
If,
$config['csrf_protection'] = TRUE;
如果将其设置为true,则需要使用form_open()
,这将自动附加ci_csrf_token
.否则,您可以将其设置为FALSE
.
If it is set to true you need to use form_open()
, this will auto append the ci_csrf_token
. Otherwise you can just set to FALSE
.
但建议将其设置为TRUE
.但是,您需要确保所有请求都包括ci_csrf_token
以及AJAX请求.
But its advisable to set it to TRUE
. But you need to make sure all your request includes the ci_csrf_token
including AJAX request.
https://www.codeigniter.com/user_guide/helpers/form_helper.html
这篇关于您请求的操作是不允许的.点火枪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!