Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Windows username of current user using php? [duplicate]

Possible Duplicate:
How to read Windows loged in username with PHP/IIS

I'm work on php tool that generate Data Access layer and generate some folders and files to user but i need to know how can i get username for current windows user to generate these folders on desktop

ex:
C:\\users\\<username>\\desktop

I need to know the username.

like image 685
Moataz Aahmed Mohammed Avatar asked Oct 05 '12 21:10

Moataz Aahmed Mohammed


People also ask

How to get Windows username in php?

If anyone else has this issue, I found this handy function on php.net (http://php.net/manual/en/function.get-current-user.php): get_current_user(); $username = get_current_user(); echo $username; This was the only way I was finally able to get the user's active directory username.

How to get username in php?

$_SESSION['loggedin'] = $row[$this->pass_column]; $_SESSION['userlevel'] = $row[$this->user_level]; What you have to do is add the $username to the session that is passed into the login function, like below; $_SESSION['username'] = $username; The username will now be stored in the session with the key username.


1 Answers

If by current windows user you mean the user running the script then that is set in an environment variable which you can get using:

<?php echo getenv("username"); ?>

If you want to get the home directory of the user running the script you should use

<?php echo getenv("HOMEDRIVE") . getenv("HOMEPATH"); ?>

This should output either C:\Users\Fred or C:\Documents and Settings\Fred depending on if you are using windows Vista/7 or windows XP.

To see all of the environment variables you can do:

<?php global $_ENV; var_dump($_ENV); ?>
like image 144
dsas Avatar answered Sep 30 '22 06:09

dsas