Re: How to get server user?

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

 



On Tuesday, Feb 17, 2015 at 1:59 am, Jeffry Killen <jekillen@xxxxxxxxxxx>, wrote:
I've been looking over the output from phpinfo to find a way
to portably get the server user name. It is not obvious to me...

Can I get that from an $_ENV or $_SERVER value?

I have a web base cms system with a file editor and
want to test for ownership of the files and directories
without having to hard code the server name.

I can get file owner ship but if I want to verify it is
the server user account, I would do:
(pseudo code)
$_name = getOwner()
if($_name == < portable reference to server user name>)
   {
   // proceed
}

This would be for enhanced access permissions analysis.
If a file is being written to by the server user (via php code)
it would be helpful to determine that to forstall error message
generation.



I can’t be absolutely certain it would universally work, but this should work on most platforms:




$user = trim(`whoami`);




Alternatively you could use http://php.net/tempnam to get a temporary filename, create and close it, then get the owner details.




However, as mentioned previously you should really be dealing with errors in a sensible way. If your script has reason to write to a file it should attempt to do so and deal with a failure. Pre-emptive programming should never take the place of defensive programming.




-Stuart




-- 

Stuart Dallas

3ft9 Ltd

http://3ft9.com/

[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