Can anyone tell me the best practice to check if the user is activated and logged-in? And how can I handle it from ajax request?
If a user is deactivated, redirect to the login page via ajax request on a controller.
I'm making a helper function and calling it in the constructor.
But it not redirecting to the login if the user is deactivated and return "Status Code: 303 See Other"
In controller:
function __construct()
{
parent::__construct();
$this->load->helper('auth_helper');
if (!auth())
{
redirect('login/login_panel');
}
}
Helper function:
function auth()
{
$CI =& get_instance();
$user = true;
if ($CI->session->userdata('user_id')) {
$CI->load->model('users_model');
$active = $CI->users_model->getActive($CI->session->userdata('user_id'));
if ($active->active == '0' || $active->active == null) {
$user = false;
}
} else {
$user = false;
}
return $user;
}
try this
function __construct()
{
parent::__construct();
$this->load->helper('auth_helper');
if (!auth())
{
header('Location: login/login_panel');
exit();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.