在 PHP 中查找 Windows 用户名 [英] Find Windows username in PHP
本文介绍了在 PHP 中查找 Windows 用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 PHP 中检索当前登录的 Windows 用户的用户名?
How can I retrieve the username of the currently logged on Windows user in PHP?
推荐答案
此代码将显示运行 PHP/WebServer 的用户名.如果你在 CLI 模式下运行这样的脚本,它会显示你的登录名,否则它会是 web 服务器用户的用户名:
This code will display username under which PHP/WebServer is run. If you run such script in CLI mode, it will show your login name, otherwise it will be username for the webserver user:
$obj = new COM("wscript.network");
echo $obj->username;
更多信息
- http://php.net/manual/en/function.com-获取.php
- http://msdn.microsoft.com/en-us/library/3fxhka75%28v=vs.85%29.aspx
另一种选择是通过 WMIC:
An Alternative would be via WMIC:
exec('wmic COMPUTERSYSTEM Get UserName', $user)
print_r($user);
有关 WMIC
的更多详细信息,请参阅
For more details on WMIC
, see
这篇关于在 PHP 中查找 Windows 用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文