I know that the command phpinfo()
returns this:
But I want to know if there is any way to capture this information (user / group) in a variable.
I found out. You can do this using:
$uid = posix_getuid();
$userinfo = posix_getpwuid($uid);
print_r($userinfo);
Or:
print posix_getpwuid(posix_geteuid())['name'];
You can use $_SERVER['USER']
.
If a person accesses site.com/files.php , $_SERVER['USER']
would be nginx
, for example. While this would be executed, via SSH (php /www/files.php) it would be the user name connected to SSH, root
for example.
Test this using:
echo $_SERVER['USER'];
You can do for example:
if($_SERVER['USER'] === 'www-data'){
//É acessado via apache
}else{
//Não acessado por apache
}