Welcome Guest, Not a member yet? Register   Sign In
How to restrict access to controller without approapriate permissions
#1

[eluser]livestrong[/eluser]
Hello, need some help from the community.

I have several admin controllers. And I want to restrict access to methods of these controllers to everybody except admin. In order to do so I added verification of user's id to the constructor. See below:
Code:
class Cities extends Controller {

    function Cities()
    {
        parent::Controller();
        $this->load->model('cities_model');    
        if ($this->session->userdata('user_id') != 1)
        {
            redirect("/");
        }
    }

    function Foo()
    {
        ...
    }

Now when I try to access any method from Cities controller, I'm redirected. That is correct. But in spite of this function is executed also. That shouldn't happen, if I'm correct.

Can anyone assist with this problem?
#2

[eluser]slowgary[/eluser]
Even though you are calling redirect(), the code continues its normal program flow. Try adding a call to die() after the redirect.
#3

[eluser]livestrong[/eluser]
Thank you, that's it!




Theme © iAndrew 2016 - Forum software by © MyBB