Open GoogleCodeExporter opened 9 years ago
Nevermind .. it seems that at least in my php .. it's not done like this
d3xt3r01 tmp # php -v
PHP 5.5.6-pl0-gentoo (cli) (built: Dec 2 2013 01:18:37)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
Piece of code that does seem to do the job:
$env = array("AUTHTYPE", "CONTEXT", "IP", "HOST", "PATH", "COOKIE",
"HTTP_HOST", "URI");
foreach($env as $v){
flog($v.'='.getenv($v));
}
Results:
2013-12-12 19:42:00 - SELECT `id`, `expiry` FROM `auth` WHERE `user` = 'dex'
AND `password` = '...' AND `enabled` = '1' AND (`expiry` > NOW() OR `expiry` =
'0000-00-00 00:00:00') LIMIT 1;
2013-12-12 19:42:00 - Yes
2013-12-12 19:42:00 - dex - ...
2013-12-12 19:42:00 - AUTHTYPE=PASS
2013-12-12 19:42:00 - CONTEXT=
2013-12-12 19:42:00 - IP=192.168.1.1
2013-12-12 19:42:00 - HOST=
2013-12-12 19:42:00 -
PATH=/bin:/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin:/usr/sbin:/usr/local/bin:
/usr/local/sbin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.3:/opt/nvidia-cg-t
oolkit/bin:/opt/cuda/bin
2013-12-12 19:42:00 - COOKIE=
2013-12-12 19:42:00 - HTTP_HOST=d3x...
2013-12-12 19:42:00 - URI=/some/index.php
Hope this saves some time .. maybe it can be modified in the example
Original comment by dex...@d3xt3r01.tk
on 12 Dec 2013 at 5:45
A cleaner way:
$env = array("AUTHTYPE", "CONTEXT", "IP", "HOST", "PATH", "COOKIE",
"HTTP_HOST", "URI");
foreach($env as $k){
$v = getenv($v);
if(empty($v)){ continue; }
flog($k.'='.$v);
}
Also, one could do it like this:
ob_start();
phpinfo(INFO_ENVIRONMENT);
$phpinfo = ob_get_contents();
ob_get_clean();
flog($phpinfo);
Original comment by dex...@d3xt3r01.tk
on 12 Dec 2013 at 5:52
[deleted comment]
Hmmm...I can confirm that the test.pipe.php script in the distribution fails to
print any environment variables on my computer either.
That was a contributed script. I didn't write it, and I don't know PHP at all.
My minimal web research suggests that the original version is kind of supposed
to work. And there ought to be a way to print out everything in the
environment, not just stuff from a list of names (we add environment variables
fairly often - I don't want to have to remember to update this script the next
time that happens). Your last version might do that, but it seems rather weird.
If we are doing sample programs, they ought to be good, generalizable samples.
I could use some input from other actual PHP programmers on the right solution
to this problem.
Original comment by j...@unixpapa.com
on 15 Jan 2014 at 2:50
It looks like the original code will work if and only if the "variables_order"
string defined in your "php.ini" file includes an "E" in it's value. On my
system it is set to
variables_order = "GPCS"
The "php.ini" file also says:
; This directive determines which super global arrays are registered when PHP
; starts up. If the register_globals directive is enabled, it also determines
; what order variables are populated into the global space. G,P,C,E & S are
; abbreviations for the following respective super globals: GET, POST, COOKIE,
; ENV and SERVER. There is a performance penalty paid for the registration of
; these arrays and because ENV is not as commonly used as the others, ENV is
; is not recommended on productions servers. You can still get access to
; the environment variables through getenv() should you need to.
So probably we should default to one of the getenv() solutions.
Original comment by j...@unixpapa.com
on 15 Jan 2014 at 3:03
Original issue reported on code.google.com by
dex...@d3xt3r01.tk
on 12 Dec 2013 at 5:35