NYCPHP Meetup

NYPHP.org

[nycphp-talk] Determining if cmd line script is running as root?

csnyder chsnyder at gmail.com
Thu Jul 26 22:06:54 EDT 2007


On 7/26/07, Michael B Allen <ioplex at gmail.com> wrote:
> Hi,
>
> How does one determine if a command line PHP script is being executed as root?
>
> If there's no posix extension there's no posix_getuid and if the user
> did 'su' and not 'su -' then the USER environment variable may not be
> root.
>
> Any other ways?
>

For what it's worth, on my linux box, su root results in the same
thing as su - root, uid==0.

It may depend on the shell in use, I don't know, but it seems pretty
important unixwise to return the correct UID no matter what the
environment says.

-- 
Chris Snyder
http://chxo.com/



More information about the talk mailing list