• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Restrict access to controller

#1
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.
Reply

#2
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
I would like to restrict public access to it, but still be able to run it with a cron job.
Reply

#4
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();
 
      

    

A good decision is based on knowledge and not on numbers. - Plato

Reply

#5
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();
 
      

    

Reply

#6
You are welcome
A good decision is based on knowledge and not on numbers. - Plato

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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