CodeIgniter Forums

Full Version: Restrict access to controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

I need to restrict access to a controller.
I have tried placing a .htaccess file inside the controllers directory with code like this:

Code:
<FilesMatch "config\.php|function\.php|include\.php">
 Order allow,deny
 Deny from all
</FilesMatch>

But it doesn't seem to work Sad

How can I restrict access to controller?

I hope somebody can point me in the right direction.

Best regards.
It depends on how you want to restrict the Controller.

If you just need to restrict it from the url CI allows an _ ( under_score ) to do that.
You can also make the methods in it private.

If you want to restrict user access then you will need to create your own method to do that.
I would like to restrict public access to it, but still be able to run it with a cron job.
You can use something like this in your __construct
PHP Code:
public function __construct()
 
   {
 
       if(!is_cli()){
 
           echo "go away!!";
 
           die();
           
// Or redirect to an other page 
 
       }
 
       parent::__construct();
 
      

    

Thank you! This is perfect for the job Smile

(11-24-2016, 12:49 AM)salain Wrote: [ -> ]You can use something like this in your __construct
PHP Code:
public function __construct()
 
   {
 
       if(!is_cli()){
 
           echo "go away!!";
 
           die();
           
// Or redirect to an other page 
 
       }
 
       parent::__construct();
 
      

    

You are welcome