-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: is_cli()
returns true
on Apache
#5336
Comments
I'd suggest the following code, inspired from Laravel: function is_cli(): bool
{
return \PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg';
} Refs:
|
It's also what Symfony does, see in VarDumper.php: \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) I investigated a bit, and it seems it would be useless to keep the |
CI3: return (PHP_SAPI === 'cli' OR defined('STDIN')); https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Common.php#L378-L382 |
PHPUnit also uses the phpdbg check, so that's probably a good addition. |
I did a bit of pondering and I think the compound -! isset($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'])
+! isset($_SERVER['REMOTE_ADDR']) && ! isset($_SERVER['HTTP_USER_AGENT']) In the original, the two server variables are evaluated as a single condition, that's why when one fails, the whole condition is true. They should be checked individually.
! isset($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']);
// ! isset(true, false)
// ! false
// true # unintended
! isset($_SERVER['REMOTE_ADDR']) && ! isset($_SERVER['HTTP_USER_AGENT']);
// ! true && ! false
// false && true
// false # intended |
It's absolutely possible for At the very most it could be considered a hint, but we definitely can't rely on it. |
I sent a PR #5393. |
PHP Version
7.4
CodeIgniter4 Version
4.1.5
Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
No response
What happened?
is_cli()
returnstrue
after upgrade to 4.1.5 from 4.0.Steps to Reproduce
Navigate to the site.
Expected Output
is_cli()
returnsfalse
.Anything else?
From https://forum.codeigniter.com/thread-80530-post-391559.html
The environment is:
$_SERVER['HTTP_USER_AGENT']
$_SERVER['argv']
$_SERVER['REMOTE_ADDR']
The text was updated successfully, but these errors were encountered: