php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76957 Missing values in $_SERVER
Submitted: 2018-10-01 18:05 UTC Modified: 2018-10-02 14:13 UTC
From: office at vargapeter dot net Assigned: cmb (profile)
Status: Not a bug Package: CGI/CLI related
PHP Version: 7.2.10 OS: Any Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: office at vargapeter dot net
New email:
PHP Version: OS:

 

 [2018-10-01 18:05 UTC] office at vargapeter dot net
Description:
------------
1)
When executing 'php -c /path-to-ini-file /path/exec.php' via the system() function in the Apache module the script 'exec.php' doesn't have HOST value in $_SERVER.

Running in the OS command line 'php -c /path-to-ini-file /path/exec.php' $_SERVER has HOST value.

I consider it inconsistent for the HOST value which is in both cases known.

2)
$_SERVER is more or less exactly the section Environment from phpinfo() function when running via system() in a browser tab.

This behavior is nowhere documented and fairly surprising.

Test script:
---------------
foo.php - calling in a browser tab:

<?php
system("php -c  /etc/php7/cli/php.ini /path/exec.php");
?>

exec.php - called a) via system() or directly from command line:

<?php
print_r($_SERVER);
?>


Expected result:
----------------
From command line AND via system() in Browser tab:
Array
(
    ...
    [HOST] => MY_HOST   <---- MISSING
    [_] => /usr/bin/php
    [PHP_SELF] => /path/exec.php
    [SCRIPT_NAME] => /path/exec.php
    [SCRIPT_FILENAME] => /path/exec.php
    [PATH_TRANSLATED] => /path/exec.php
    [DOCUMENT_ROOT] =>
    [REQUEST_TIME_FLOAT] => 1538415804.9271
    [REQUEST_TIME] => 1538415804
    [argv] => Array
        (
            [0] => /path/exec.php
        )

    [argc] => 1
)



Actual result:
--------------
Totally different output; even running exec.php as PHP CLI version. No HOST entry.

This is the output from system() in a browser tab:


Array
(
    [APACHE_CONF_INCLUDE_FILES] => 
    [mpm_found] => true
    [APACHE_CONF_INCLUDE_DIRS] => 
    [SYSCONFIG_FILE] => /etc/sysconfig/apache2
    [APACHE_START_TIMEOUT] => 2
    [HTTPD_MODULE_IDS] =>  actions_module alias_module ...
    [APACHE_SERVERNAME] => 
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    [APACHE_HTTPD_CONF] => 
    [PWD] => /userdata/dev1/faewe.technology
    [APACHE_SERVERTOKENS] => ProductOnly
    [NOTIFY_SOCKET] => /run/systemd/notify
    [APACHE_SERVERADMIN] => 
    [HTTPD_MODULE_PATHS] =>  /usr/lib64/apache2-prefork/mod_actions.so ...
    [SHLVL] => 1
    [APACHE_ACCESS_LOG] => /var/log/apache2/access_log combined
    [LC_CTYPE] => en_US.UTF-8
    [APACHE_LOGLEVEL] => warn
    [APACHE_USE_CANONICAL_NAME] => off
    [APACHE_EXTENDED_STATUS] => off
    [APACHE_MODULES] => actions ... php7
    [APACHE_SERVER_FLAGS] => 
    [HTTPD_MPM] => prefork
    [APACHE_SERVERSIGNATURE] => off
    [sysconfig_loaded] => true
    [APACHE_MPM] => 
    [OLDPWD] => /
    [_] => /usr/bin/php
    [PHP_SELF] => /path/exec.php
    [SCRIPT_NAME] => /path/exec.php
    [SCRIPT_FILENAME] => /path/exec.php
    [PATH_TRANSLATED] => /path/exec.php
    [DOCUMENT_ROOT] => 
    [REQUEST_TIME_FLOAT] => 1538415816.209
    [REQUEST_TIME] => 1538415816
    [argv] => Array
        (
            [0] => /path/exec.php
        )

    [argc] => 1
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-01 19:08 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2018-10-01 19:08 UTC] requinix@php.net
I don't believe PHP is creating a "HOST" value. Are you sure you aren't inheriting that from an exported environment variable?
 [2018-10-02 08:32 UTC] office at vargapeter dot net
-Status: Feedback +Status: Open
 [2018-10-02 08:32 UTC] office at vargapeter dot net
Good question. How can I check it?
 [2018-10-02 08:36 UTC] office at vargapeter dot net
Sorry! I meant HOSTNAME not HOST. I apologize for the confusion!

So HOSTNAME is missing.
 [2018-10-02 08:54 UTC] gabri dot ns at gmail dot com
HOSTNAME is shell variabel. when you are running php from web, almost all shell variable were stripped.
 [2018-10-02 14:13 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-10-02 14:13 UTC] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 02:01:29 2024 UTC