Re: whoami explanation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




This really needs some explanation
I found this on the web:
<?php echo `whoami`; ?>
with it there was the comment "the direction of those single-quotes matters"
(WHY ?)
and it works....

But this (_*FROM THE PHP MANUAL***_ * -  exec()* executes the given
/command/ ) does not,
COPIED AND PASTED:
|<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?> |
What is going on here?
And I often find such discrepancies in examples - and some wonder why I
seem to be so stupid... and don't know the fundamentals... :-\
Didn't have the time to read the whole thread. Sorry for being so lame.

I will have to mention that whoami is actually "id -un" and probably if you need to get user information from the shell IMHO you should better use the id command or a better solution could be the posix_getuid() function.

If you need to find the owner of the current script you could use something like get_current_user().

<?php
echo 'Current script owner: ' . get_current_user();
echo "<br>Current proccess id from the shell: ";
echo `id`;
echo "<br>Current proccess id from the posix getuid: ";
echo posix_getuid();
?>

btw I think it would be nice to have a function that can give you the user that actually runs the script (apache ,www) instead of using the command line. The posix functions AFAIK can give you only the ids (uid,gid etc) about a process.

--
Thodoris


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux