[英]Is there a way to get the current Windows login username using Html, php, etc.?
I have had this problem for some time.我有这个问题有一段时间了。 I have set up a Windows IIS.
我已经设置了 Windows IIS。 But I would like to read the Windows username of the person who calls the page.
但我想阅读调用该页面的人的 Windows 用户名。
On other sites there is as solution: $_SERVER['REMOTE_USER'];在其他网站上有解决方案: $_SERVER['REMOTE_USER']; But this did not work for me.
但这对我不起作用。 I guess because the user who calls the page is an anonymous user.
我猜是因为调用该页面的用户是匿名用户。 As an idea to solve this, I turned on authentication in Windows IIS Manager.
为了解决这个问题,我在 Windows IIS Manager 中打开了身份验证。 IIS-Manager Authentication
IIS 管理器身份验证
But that didn't solve my problem either.但这也没有解决我的问题。 My question now is: Does anyone have an idea how I could solve this problem?
我现在的问题是:有人知道我如何解决这个问题吗?
Yes there is a way to do this.是的,有办法做到这一点。
Since you are using Windows IIS you should be able to use this exec()
command.由于您使用的是 Windows IIS 您应该能够使用此
exec()
命令。
exec("wmic /node:$_SERVER[REMOTE_ADDR] COMPUTERSYSTEM Get UserName", $user);
echo($user[1]);
I got this answer from this question here.我从这个问题here得到了这个答案。
I tested it out on my windows machine locally, and it worked like a charm for me.我在本地的 windows 机器上对其进行了测试,它对我来说就像一个魅力。
for me worked:对我来说工作:
<?php
$username = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo($username);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.