note 114048 added to reserved.variables.server
| From: | info at salientdigital dot com | Date: | Mon, 06 Jan 2014 20:46:10 +0000 |
| Subject: | note 114048 added to reserved.variables.server | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198129@lists.php.net to get a copy of this message | ||
A word of caution...
If you have some PHP code or file that is included from within a web request via Apache + PHP, as
well as from a command line script, be very careful to inspect the keys inside of $_SERVER that you
intend to use.
The keys and values are different, and in fact, it also matters if you are running as your_user,
sudo php from your_user, or from root.
For example, I just found out that $_SERVER['PWD'] is not available if you run from the
command line via sudo (PHP 5.2x, CentOS, YMMV).
To make a test, create a file called server.php with the following content:
<?php
var_dump($_SERVER);
?>
Then from the commandline:
your_account/dir #$ php server.php > your_account_server.txt
your_account/dir #$ sudo php server.php > your_account_sudo_server.txt
your_account/dir #$ sudo bash
root/dir #$ php server.php > root_server.txt
Now you can diff the output of each of these three files and inspect against what you get when
viewing the $_SERVER section of phpinfo() from a web request. You may find the differences to be
quite striking, in all, four different ways to run the same PHP file!
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/reserved.variables.server.php
Edit -- https://master.php.net/note/edit/114048
Del: integrated -- https://master.php.net/note/delete/114048/integrated
Del: useless -- https://master.php.net/note/delete/114048/useless
Del: bad code -- https://master.php.net/note/delete/114048/bad+code
Del: spam -- https://master.php.net/note/delete/114048/spam
Del: non-english -- https://master.php.net/note/delete/114048/non-english
Del: in docs -- https://master.php.net/note/delete/114048/in+docs
Del: other reasons-- https://master.php.net/note/delete/114048
Reject -- https://master.php.net/note/reject/114048
Search -- https://master.php.net/manage/user-notes.php