确定通过web服务器在php中运行shell时的确切用户?
通过web访问php页面时:确定通过web服务器在php中运行shell时的确切用户?,php,shell,webserver,Php,Shell,Webserver,通过web访问php页面时: <?php print '<pre>'."\n"; print 'Current script owner: '."\n"; print get_current_user()."\n"; print "\n"; print '$USER: '."\n"; passthru('print $USER'); print "\n"; 为什么shell用户不等于当前脚本所有者?当通过web服务器在php脚本中运行shell时,如何确定用户?环境变量由
<?php
print '<pre>'."\n";
print 'Current script owner: '."\n";
print get_current_user()."\n";
print "\n";
print '$USER: '."\n";
passthru('print $USER');
print "\n";
为什么shell用户不等于当前脚本所有者?当通过web服务器在php脚本中运行shell时,如何确定用户?环境变量由
login
程序填写。由于PHP是作为后台守护进程运行的,因此通常不会设置该变量。您可以使用putenv
进行设置:
为什么shell用户应该等于脚本的所有者?如果您想获取流程用户名,文档页面上的注释中有很多建议:我发现
posix\u getpwuid(posix\u geteuid())
也是danny,而shell\u exec('whoami')
是空的。如何在通过web php执行系统命令时配置shell用户?$user
和whoami
由login
填写。因为PHP是作为守护进程运行的,所以它没有得到这些变量。我已经让它工作了,谢谢你的提示。但是posix_getpuid(posix_geteuid())是一个包含信息的数组;因此,正确的脚本应该是:
Current script owner:
danny
$USER:
$user = posix_getpwuid(posix_geteuid());
putenv('USER='.$user['name']);