Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Error encountered when running Command Line using CodeIgniter 2.xx

I have followed the exact guide that is provided on the official codeigniter website for running the CLI (command-line interface) tool. https://www.codeigniter.com/userguide2/general/cli.html

My controller is...

<?php
class Tools extends CI_Controller {

    public function message($to = 'World')
    {
    echo "Hello {$to}!".PHP_EOL;
    }

} ?>

When I run the following command from my CMD I get the following output (and error) in the command line window:

php index.php tools message

<h4>A PHP Error was encountered.</h4>
<p>Severity: Notice</p>
<p>Message: Undefined index: REMOTE_ADDR</p>
<p>Filename: core/Input.php</p>
<p>Line Number: 351</p>
.....
<h4>A PHP Error was encountered</h4>
<p>Message: Cannot modify header information - headers already sent by (output at C:{systempath}\system\2.1.4\core\Exceptions.php:185)</p>
<p>Filename: libraries/Session.php</p>
<p>Line Number: 675</p>

</div>Hello World!

Can anyone explain why I am getting this problem? I am following the tutorial as per the official Codeigniter CLI tutorial too - any ideas? I am using CodeIgniter 2.1.4 with XAMPP (Windows).

like image 378
Zabs Avatar asked Aug 06 '13 14:08

Zabs


1 Answers

https://github.com/EllisLab/CodeIgniter/issues/1890

Just replace $_SERVER['REMOTE_ADDR'] with $this->server('remote_addr') at the line that generates the notice. - modify /system/core/Input.php line 351

like image 159
Zabs Avatar answered Oct 16 '22 03:10

Zabs