使用php获取当前用户的Windows用户名? [英] Get Windows username of current user using php?

查看:442
本文介绍了使用php获取当前用户的Windows用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何使用PHP/IIS读取Windows登录用户名

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

我正在使用php工具生成数据访问层并为用户生成一些文件夹和文件,但我需要知道如何获取当前Windows用户的用户名,以便在桌面上生成这些文件夹

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. Thanks

推荐答案

如果当前Windows用户是指运行脚本的用户,则该脚本是在您可以使用的环境变量中设置的:

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"); ?>

这应该输出C:\ Users \ Fred或C:\ Documents and Settings \ Fred,具体取决于您使用的是Windows Vista/7还是Windows XP.

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); ?>

这篇关于使用php获取当前用户的Windows用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆