Restrict access to MY_Controller functions

#1
[eluser]dynZack[/eluser]
How do you restrict access in certain functions defined within MY_Controller?

For example:

Code:
class  MX_Controller  extends  Controller  
{
    
    function MX_Controller()
    {
        parent::Controller();
    
    }
      
      
    function set_cookies($params = array())
    {
        ...
    }

}

Going to http://www.example.com/set_cookies outputs a blank page and not a 403 error.

How to make sure that access is forbidden, output a message and redirect to home page?

#2
[eluser]mddd[/eluser]
If you want a controller method to never be available to the public (that is: you can only call it from within your own code) you can start the name with a _. CI will not make the method available to be called from the URI.
Note: this has nothing to do with being in a controller or in MY_Controller.

Like this:
Code:
function _set_cookies()
{
  // this code can NOT be called like www.example.com/_set_cookies.
}

function other_function()
{
  // this can be called through www.example.com/other_function
  // and from here you can call your other method
  $this->_set_cookies()
}

#3
[eluser]dynZack[/eluser]
Thanks for the quick answer!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.