get_current_user

(PHP 3, PHP 4, PHP 5)

get_current_user --  Gets the name of the owner of the current PHP script

Description

string get_current_user ( void )

Returns the name of the owner of the current PHP script.

See also getmyuid(), getmygid(), getmypid(), getmyinode(), and getlastmod().



get_current_user
justin samuel
08-Oct-2005 11:45
to get the username of the process owner (rather than the file owner), you can use:

<?php
$processUser
= posix_getpwuid(posix_geteuid());
print
$processUser['name'];
?>
justin samuel
08-Oct-2005 11:25
with 4.3.11 (and i assume all other versions):

get_current_user() does *not* get the name of the user the script is running as, as stated in the comment below.  instead, it "gets the name of the owner of the current PHP script" (as stated in the description above) --- that is, the owner of the file, not the owner of the process.

if the script file is owned by root but php scripts are being being run as apache (for example, you're using mod_php because you don't mind your shared hosting environment being insecure), when you request your script through the webserver, get_current_user() will return "root".  that does not mean your script is running as root.
joho at pop3 dot nu
06-Oct-2005 05:43
get_current_user () returns the owner of the process running the script. In most cases, this will be the web server user ("nobody", "httpd", "apache", etc).
SiliconExpress at Techie dot com
19-Jun-2005 07:34
The 'constant' __FILE__ works easier ...

Example :

echo __FILE__;

Returns - '/home/username/public_html/filename.php'

This works INSIDE includes!!!  It saved me a bunch of problems..  If I want to make sure somebody does not load a file directly this is supposed be be an include this is the code I use...  Hope it helps you as much as it does me!  :)

//If user tries to load page directly the redirect to the home page
if ($_SERVER['SCRIPT_FILENAME'] == __FILE__) {
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: /");
   echo "DO NOT TRY TO ACCESS THIS FILE DIRECTLY\r\n";
   exit;}
comicforum at lelon dot net
22-Apr-2005 02:51
Under windows, this function does not work the same in Apache as it does in IIS.  If you want the user name in apache, you have to use...

getenv("REMOTE_USER");
chris
04-Jan-2005 07:36
If you want to get the absolute name of the file you are currently on, use this:

<?
$rest
= explode("php.net/", $PHP_SELF);
$rest = $rest[0];
echo(
"/home/".get_current_user()."/public_html".$rest);
?>
Just change php.net/ to your site's domain and a slash.

<get_cfg_varget_defined_constants>
 Last updated: Tue, 15 Nov 2005