I have a problem with the login in codeigniter at the time of login,

0

I have this problem I have already prepared but when I enter the login I fill in the spaces and to enter at the moment of entering administrator mode, it returns me to the same start ...

Here I enclose my login driver

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('personal_model');
    }

    public function index()
    {
        $this->load->view('admin/login/index');
    }

    public function logear(){

        $usuario = $this->input->post('usuario');
        $clave = $this->input->post('clave');


        $result = $this->personal_model->logear($usuario, $clave);

        if ($result > 0){
            // obtenemos el usuario y el id del personal 
            $_SESSION['usuario'] = $usuario;
            $_SESSION['id'] = $result['id'];
            $_SESSION['logged_in'] = TRUE;

            redirect('admin/');
        }else{
            redirect('admin/login');
        }

    }

    public function salir(){
        $this->session->sess_destroy();
        redirect('admin/');
    }


}

Here's the model

    class Personal_model extends CI_Model {

    public function logear($usuario, $clave) {
        $this->db->where('usuario', $usuario);
        $this->db->where('password', $clave);
        $query = $this->db->get('usuarios');
        return $query->row_array();

    }
}

and here the view

    </head>
<body>
    <div class="container">

        <div class="row">
            <div class="col-md-12">
                <div class="btn-group  pull-right">
                    <a href="<?php echo base_url(); ?>" class="btn btn-default"><i class="fa fa-home"></i> Inicio</a>
                </div>
            </div>
        </div>

        <?php echo form_open('admin/login/logear','class="form-signin"'); ?>
        <h2 class="form-signin-heading">Iniciar sesión</h2>
        <input type="text" name="usuario" class="form-control" placeholder="Usuario" required autofocus>
        <input type="password" name="clave" class="form-control" placeholder="Contraseña" required>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Entrar</button>
    </form>
</div>
</body>
</html>
    
asked by DAVE 26.09.2018 в 22:57
source

1 answer

0

The problem is that when you do the login redirects for the admin index but the admin index is loading the login view again, so you would have to define what you are going to show in the admin index other than

EDITED:

In the index you can see if the user is already logged in, load the view you want and if not load the login:

public function index()
{
  if($_SESSION['logged_in']){
     $this->load->view('admin/vista/administrador')
  }else{
     $this->load->view('admin/login/index');
  }
}
    
answered by 27.09.2018 в 19:03