Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session/Input and Crontab/CLI #1890

Closed
matalina opened this issue Oct 15, 2012 · 17 comments
Closed

Session/Input and Crontab/CLI #1890

matalina opened this issue Oct 15, 2012 · 17 comments

Comments

@matalina
Copy link

I am running a serveral cronjobs on our intranet. Before I upgraded to the current release of CI I was running error free.

Now I am getting:

<div>

<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>

</div><div>

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Cannot modify header information - headers already sent by (output started at /usr/local/www/webdev/corp_intranet/system/core/Exceptions.php:185)</p>
<p>Filename: libraries/Session.php</p>
<p>Line Number: 675</p>

</div> 

I know what the error means, and I can fix it myself, but I wanted to know if there is anyone else having this issue. It only happens when I run on the cli/cronjobs regular pages run fine.

@ckdarby
Copy link
Contributor

ckdarby commented Oct 15, 2012

Which version were you & did you upgrade to?

This is most likely because you replaced the index.php & now the development environment is set as development which will display all php errors on the page this includes notices & warnings.

@matalina
Copy link
Author

I don't recall what I was at 2.1.1 to whatever is most recent. I did not replace the index.php I only changed the system directory and the mimes.php file as per the instructions in the upgrade documenation from the version I was at the the new version.

I was running development environment before and I am still running it now. It ONLY happens in the CLI, and not on a regular page.

@narfbg
Copy link
Contributor

narfbg commented Oct 15, 2012

Yes, other people will experience this as well. See this forum thread: http://codeigniter.com/forums/viewthread/227672/#1034205

@abfan1127
Copy link

I auto-load sessions. Sessions calls the the function. Either the sessions lib should detect CLI and disable itself, or the function should be tolerant. I'll do a pull request, just let me know the direction.

@narfbg
Copy link
Contributor

narfbg commented Oct 23, 2012

I guess I haven't made it clear enough, with linking forum threads and stuff ...
Sorry about that, here's a FAQ of some kind: :)

  • Yes, these notices have not been triggered in previous versions.
  • No, that is not a bug - it is not the framework's fault that you're loading an HTTP Session class under a CLI environment.
  • Yes, we acknowledge that it's convenient and reasonable to be able to load the Session class under CLI anyway.
  • Yes - it has already been fixed for future versions, the "problem" only exists in CI 2.1.3.

@abfan1127
Copy link

I started using CodeIgniter because it was supposed to be robust. Libraries should be robust to all environments, including CLI.

But all of that is moot if its fixed.

"Its fixed" is all that matters.

@donjakobo
Copy link

So where is this "fix"? Can I apply a patch to my current 2.1.3?

@Relequestual
Copy link

I would also like to know if I can manually patch this before the next release.

@narfbg
Copy link
Contributor

narfbg commented Dec 10, 2012

Just replace $_SERVER['REMOTE_ADDR'] with $this->server('remote_addr') at the line that generates the notice.

@donjakobo
Copy link

@narfbg 👍 thanks!

@aderowbotham
Copy link

Thanks for the patch.

For anyone unclear, modify /system/core/Input.php line 351 as per @narfbg 's comment above.

@dpistole
Copy link

@narfbg ty

@tonywcm
Copy link

tonywcm commented Jul 22, 2013

@narfbg
still work in 2.1.3

@aderowbotham
Copy link

Having applied this patch I've noticed my ci_sessions table was populated with the ip_address 0.0.0.0.

You must have $this->server('REMOTE_ADDR') with REMOTE_ADDR in uppercase otherwise it returns false.

This causes $this->valid_ip to fail so it defaults to 0.0.0.0

@aegiz
Copy link

aegiz commented Jan 23, 2014

thanks for the tip @aderowbotham 👍

@kishor10d
Copy link

This is issue is resolved in current version of CodeIgniter-2.2.2
I am using this version for my project and confirmed after checking the code on line no. 351

@whyscream
Copy link

This issue still exists in CI 2.2.3, the error has moved to line 352. Looking at git history, I can't seem to find when the fix as described in #1890 (comment) was ever committed.

Please re-open, the fix is trivial and known, so please apply it.

Output:

$ php index.php utils
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<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: 352</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Cannot modify header information - headers already sent by (output started at /var/www/domain.tld/backend-app/system/core/Exceptions.php:186)</p>
<p>Filename: libraries/Session.php</p>
<p>Line Number: 689</p>

</div>

michael-dev pushed a commit to michael-dev/agendav that referenced this issue Aug 30, 2017
* Path for autoload.php was wrong
* CodeIgniter bug for CLI mode: bcit-ci/CodeIgniter#1890
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests