CodeIgniter Forums
How to restrict access to controller without approapriate permissions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to restrict access to controller without approapriate permissions (/showthread.php?tid=27806)



How to restrict access to controller without approapriate permissions - El Forum - 02-21-2010

[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?


How to restrict access to controller without approapriate permissions - El Forum - 02-21-2010

[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.


How to restrict access to controller without approapriate permissions - El Forum - 02-21-2010

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