I cannot find a way to get the user's home directory (e.g. / home / jack, something in bash) in PHP using CGI (suPHP). The $ _ENV array is empty, and getenv ('HOME') returns nothing.
The reason I want to do this is because, in the absence of a configuration that says otherwise, I want to find the variable files used by my application in /home/user/.myappnamehere, as most Linux applications do.
I built something, but this is not the best; Although it works, it takes a lot about the system (e.g. having / etc / passwd)
$usr = get_current_user();
$passwd = file('/etc/passwd');
$var = false;
foreach ($passwd as $line) {
if (strstr($line, $usr) !== false) {
$parts = explode(':', $line);
$var = realpath($parts[5].'/.report');
break;
}
}
source
share