Welcome Guest, Not a member yet? Register   Sign In
Command Line: IS_CLI
#1

[eluser]Unknown[/eluser]
Hi,

I cannot find any information on the IS_CLI constant(?) described in the documentation at http://ellislab.com/codeigniter/user-gui...l/cli.html.

Not super important but I would like to protect a controller from being accessed outside of CLI.

Thanks!
#2

[eluser]Seb[/eluser]
Not sure about the IS_CLI, but you can use the indication given on http://ellislab.com/codeigniter/user-gui...input.html :

Code:
$this->input->is_cli_request()
#3

[eluser]mrmeyers99[/eluser]
Yeah, I think that the User Guide needs to be updated on this. It just says to use IS_CLI, but doesn't say what it is...
Code:
$this->input->is_cli_request()
worked for me though.
#4

[eluser]Unknown[/eluser]
Forgive me for asking, I'm a newbie at Codeigniter. But where is the
Code:
$this->input->is_cli_request()
supposed to go?
#5

[eluser]Unknown[/eluser]
/system/core/Input.php
#6

[eluser]Seb[/eluser]
No, you have to use it in your controller, if you want to check if the request is from command line (cli) or from a HTTP request.
#7

[eluser]Tiến Thành[/eluser]
[quote author="FarCoder" date="1314097510"]Hi,

here is a use of this example:
Code:
public function cli()
{
    if ($this->input->is_cli_request()){
        echo "access from CLI".PHP_EOL;
    } else {
        echo "access is NOT from CLI".PHP_EOL;
    }
}

now if you access through CLI like:
Code:
php index.php yourcontroller cli
you will get:
Code:
access from CLI

otherwise if you visit this link through your browser you will get:
Code:
access is NOT from CLI

Hope that explains it all.[/quote]

I write a controllers Test.php with code:
Code:
<?php
  class Test extends Controller{
      public function __construct(){
          parent::Controller();            
      }
      public function index(){
          $CI = & get_instance();
          /*echo $this->input->ip_address();
          echo $this->input->is_cli_request();  */
          if($this->input->is_cli_request()){
              echo "Run by CLI";
          }else{
              echo "not inaccessible";
          }
          
      }
  }
?>
when i execute in browser, it inform error: Fatal error: Call to undefined method CI_Input::is_cli_request() in C:\xampp\htdocs\classbook\www\system\application\controllers\test.php on line 10,
please help me to fix it.
#8

[eluser]CroNiX[/eluser]
1) Your controller is supposed to extend CI_Controller, not Controller
2) You don't need to use get_instance() from within a controller (you do in a library or helper). The CI instance is already merged into $this in controllers. However this isn't working because of your error in #1.
#9

[eluser]Tiến Thành[/eluser]
May be My CI version is older so that i have to write
Code:
class Test extends CI_Controller{
      public function __construct(){
          parent::construct();  
          if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');          
      }

, i can't use extends CI_Controller. Pls help me.
#10

[eluser]CroNiX[/eluser]
Well then input::is_cli_request() probably isn't in your version. It's in 2.x. Have you checked the docs that were included in the version you downloaded? The docs on the site are for the current version, 2.1.3.




Theme © iAndrew 2016 - Forum software by © MyBB