Sto provando a creare un semplice sistema di login in codeigniter. Quando clicco sul mio pulsante di accesso ho un errore:L'azione richiesta non è consentita. Codigniter
The action you have requested is not allowed.
Quando apro la mia console vedo questo:
POST
http://localhost/PHP/PROJECT/CodeIgniter/
403 (Forbidden)
Questa è la mia opinione:
<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>
Questo è il mio modello:
<?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();
}
}
e questo è il mio controller:
<?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");
}
}
Qualcuno sa come risolvere questo problema?
Grazie!
la sua non è una buona pratica di avere un pulsante di pulsante di tipo in un modulo. Prova con il tipo di pulsante submit o intput type invia –