i tried to check if user has session in login page, if he has session and role id this controller will redirect to certain controller. but it gave me error "The page isn’t redirecting properly"
instead.
here's my code
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Auth extends CI_Controller
{
public function __construct()
{
parent::__construct();
if (!$this->session->userdata('username') == null) {
if ($this->session->userdata('role_id') == 1) {
redirect(base_url('back/admin'));
} else {
redirect(base_url('back/user'));
}
} else {
redirect(base_url('back/auth'));
}
}
public function index()
{
$data = ['title' => 'Log-in page'];
$this->form_validation->set_rules('un', 'Username', 'required|trim');
$this->form_validation->set_rules('pw', 'Password', 'required|trim');
if ($this->form_validation->run() == false) {
$this->load->view('back/login', $data);
} else { }
}
public function logout()
{
$this->session->unset_userdata('username');
$this->session->unset_userdata('role_id');
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">you\'re session has been deleted</div>');
redirect(base_url('back/auth'));
}
public function errorp()
{
// $this->load->view('back/error');
echo 'not authorized';
}
}
i tried many things to solve this redirect error, but still can't find way how to fix this or the way i'm redirect was wrong ?