PHP - Display current user using exec whoami
by
Jeremy Canfield |
Updated: October 11 2022
| PHP articles
exec can be used to run a command on the PHP server. For example, if the PHP server is a Linux system, exec could be used to run Linux command whoami.
<?php
$whoami = exec("whoami", $output, $return);
print_r($output);
echo "whoami = $whoami";
echo "Return Code = $return";
?>
Something like this should be returned which shows that you are user www-data.
Array ( [0] => www-data )
whoami = www-data
Return Code = 0
Did you find this article helpful?
If so, consider buying me a coffee over at