8

I need to restrict a controller in CI 2 to only run from command line. The other controllers in the application are accessible from the web.

What's the best way to do it?

1 Answer 1

18

You might want to check if is a CLI request:

class Mycontroller extends CI_Controller {

   function __construct()
   {
     parent::__construct();

     if(!$this->input->is_cli_request())
     { 
       // echo 'Not allowed';
       // exit();
     }
   }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.