I want user to not access certain method of controller when session is not set. For this I can check session in all method and if session is set then only go to furthur else redirect to specific page. Since I have many method that I don't want user to take access if session is not set. Its bulk to go through all method and check session. Are there any shortcut way to obtain this functionality.
I tried checking session is constructor method of controller but it works for all method. But I want only specific method to block if session is not set. How to do it.
Example:
class dashboard extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('session');
$this->load->model('dbmodel');
$this->load->helper('url','form');
//verified user check
if($this->session->userdata("unverified") != FALSE) {
redirect("verify_user");
}
}
//verified user check
}
Above code, redirects to verify_user controller as soon as 'unverified' session is found when user go to dashboard controller. But I want to give access to some method of dashboard controller. Not all method. Where as this code redirects whenever session is found and don't give access to any method of dashboard controller.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…