1
I figured it out. You can do it using:
$uid = posix_getuid();
$userinfo = posix_getpwuid($uid);
print_r($userinfo);
Or:
print posix_getpwuid(posix_geteuid())['name'];
1
3
I figured it out. You can do it using:
$uid = posix_getuid();
$userinfo = posix_getpwuid($uid);
print_r($userinfo);
Or:
print posix_getpwuid(posix_geteuid())['name'];
1
You can use the $_SERVER['USER']
.
If a person accessed site.com/.php file, the $_SERVER['USER']
would be the nginx
, for example. While running, via SSH (php /www/.php file) it would be the respective name of the user 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
}
Browser other questions tagged php apache
You are not signed in. Login or sign up in order to post.
I think that
Apache
does not return$_SERVER['USER']
. Mine doesn’t come back. I’m not sure, but I believewww-data
is not an exclusive user ofApache
. Anyway,$_SERVER
will not return what I need because it has script references, and not service.– ShutUpMagda