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

老子叫甜甜 提交于 2019-11-28 10:10:51

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); ?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!