I have a function which restricts access to some of the places on my site. In this code, the userGroup must be ‘user’ for the person to get through to the links on the site. However, I have recently added the userGroup ‘vip’ but they cannot access the links because the parameter passed in the method is only ‘user’. I’m not really sure what I have to do in order to make it work with both ‘user’ and ‘vip’…. But here is my code:
The method $this->access->restrict('user'); is called here:
class MY_User extends MY_Controller {
function MY_User() {
parent::MY_Controller();
// Protect the user area
$this->access->restrict('user');
// Don't want to cache this content
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
$this->output->set_header("Pragma: no-cache");
}
}
and gets passed to the restrict() function:
function restrict($userGroup = FALSE)
{
if($userGroup == 'logged_out')
{
if ($this->CI->user->id > 0)
{
redirect('user');
}
}
else if($this->CI->user->id < 0)
{
$this->CI->session->set_flashdata('referrer', $this->CI->uri->uri_string());
redirect();
} else if($this->CI->user->userGroup != 'admin'){
if ($userGroup AND $this->CI->user->userGroup !== $userGroup)
{
$this->CI->session->set_flashdata('referrer', $this->CI->uri->uri_string());
redirect();
}
}
}
I realize I must create a new parameter in
function restrict($userGroup = FALSE)
and
$this->access->restrict('user');
but I am not sure what to do after that
I found a solution!
I changed:
to:
And a second solution that works (thank you nickb: