0
I’m starting with codeigniter, but I have a little problem: When logging in, it doesn’t leave the incorrect password and email if. Form fields are correct and bank.
Can you help me?
This is the controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class login extends CI_Controller {
public function entrar(){
$mensagem = null;
if($this->input->post('acessar') === 'acessar'){
$this->form_validation->set_rules('user', 'email', 'required|valid_email');
$this->form_validation->set_rules('senha', 'senha', 'required|min_length[5]|max_length[40]');
if($this->form_validation->run() === true){
$this->load->model('LoginModel');
$email = $this->input->post('user');
$senha = md5($this->input->post('senha'));
$loginExistente = $this->LoginModel->verificaLogin($email,$senha);
if($loginExistente === true){
$usuario = $loginExistente;
$session = array(
'user' => $usuario['email'],
'nome' => $usuario['nome'],
'logado' => true
);
$this->session->set_userdata($session);
redirect('administracao/index');
}else{
$mensagem = array('class' => 'danger',
'mensagem' => 'Login inválido, e-mail ou senha incorretos.'.$email.' '.$senha
);
}
}else{
$mensagem = array('class' => 'danger',
'mensagem' => 'Foram encontrados erros no login </br>'. validation_errors()
);
}
}
$dados = array('alerta' => $mensagem);
$this->load->view('login/index', $dados);
}
public function sair(){
$this->session->sess_destroy();
redirect('login/entrar');
}
}
This is the model
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class LoginModel extends CI_Model {
public function verificaLogin($email,$senha){
$this->db->from('useradmin');
$this->db->where('email', $email);
$this->db->where('senha', $senha);
$usuario = $this->db->get();
print_r($usuario); die();
if($usuario->num_rows() > 0){
$user = $usuario->result_array();
return $user[0];
}else{
return false;
}
}
}
which returned with print_r
CI_DB_mysqli_result Object ( [conn_id] => mysqli Object ( [affected_rows] => 0 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: f373ea5dd5538761406a8022a4b8a374418b240e $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 5 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.6.21 [server_version] => 50621 [stat] => Uptime: 170781 Threads: 1 Questions: 3782 Slow queries: 0 Opens: 315 Flush tables: 1 Open tables: 106 Queries per second avg: 0.022 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 634 [warning_count] => 0 ) [result_id] => mysqli_result Object ( [current_field] => 0 [field_count] => 5 [lengths] => [num_rows] => 0 [type] => 0 ) [result_array] => Array ( ) [result_object] => Array ( ) [custom_result_object] => Array ( ) [current_row] => 0 [num_rows] => [row_data] => )
it arrives to check if there is the Login??
– Sr. André Baill
Can you tell what stage the function is at? using print_r and die()??
– Sr. André Baill
Make intuitive titles to the problem, look at other questions on the site and follow their example, write HELP, HELP, PLEASE does not make the question more urgent, everyone see here needing help, write HELP, HELP, PLEASE, PLEASE is totally redundant, be objective while writing. Understand as a constructive criticism.
– Guilherme Nascimento