简体   繁体   English

如何从我的PHP应用程序中获取用户的Windows用户名?

[英]How can I get a user's Windows username from my PHP app?

My reason for posting here, is because it is still unclear to me what specific requirements must be met in order to accomplish this. 我在这里发帖的原因是因为我仍然不清楚为了实现这一目标必须满足哪些具体要求。

We run our PHP apps on an iSeries Apache web server. 我们在iSeries Apache Web服务器上运行我们的PHP应用程序。 All of our users are on IE. 我们所有的用户都在IE上。 We do use AD for our usernames inside our company network. 我们确实在公司网络中使用AD作为用户名。

The current apache server setup does not require any users to log in to our pages... if you are on our network, you have access to the page. 当前的apache服务器设置不需要任何用户登录我们的页面...如果您在我们的网络上,则可以访问该页面。

Is there a way (through LDAP or other means) of getting the logged on windows username? 是否有办法(通过LDAP或其他方式)获取登录的Windows用户名? A final last resort, would be to redirect the users to an ASP.NET site hosted on our windows servers, and pass the username back to the PHP app. 最后的最后手段是将用户重定向到我们的Windows服务器上托管的ASP.NET站点,并将用户名传递回PHP应用程序。 But again, this is a very last resort. 但同样,这是最后的手段。

The link here: Can you get a Windows (AD) username in PHP? 链接在这里: 你能用PHP获得一个Windows(AD)用户名吗? has quite a few good suggestions, however the AUTH_USER variable IS empty as mentioned in the link... and i dont think the iSeries Apache server can implement Windows integrated auth. 有一些很好的建议,但AUTH_USER变量是空的,如链接中所提到的...我不认为iSeries Apache服务器可以实现Windows集成身份验证。

If someone could explain my options, and (if possible) the difficulty of those options... it would be grealy appreciated. 如果有人可以解释我的选择,并且(如果可能的话)这些选项的难度......那将是非常感激的。 Please be as specific as possible as I am not experienced with LDAP or server configurations. 请尽可能具体,因为我对LDAP或服务器配置没有经验。

You can get it from an ActiveX object and JavaScript since you're using IE. 您可以从ActiveX对象和JavaScript中获取它,因为您使用的是IE。 To get this into PHP, maybe include it as a hidden field in a login page? 要将其添加到PHP中,可能将其作为登录页面中的隐藏字段包含在内?

try {
  var activex = new ActiveXObject('WScript.Network');
  document.write(activex.userName);
} catch (ex) {
  document.write("unable to get user info");
}

Make sure that you have added this site to the browser's trusted zone and enabled scripts for it to run. 确保已将此站点添加到浏览器的受信任区域并启用脚本以使其运行。

From my experience writing SSO handling for PHP apps, you can make this work using a combination of mod_auth_ntlm and Kerberos (check out this link , it's very close to what I remember, though my original setup was ~5 years ago on a Gentoo box). 根据我为PHP应用程序编写SSO处理的经验,你可以使用mod_auth_ntlm和Kerberos的组合来完成这项工作(看看这个链接 ,它非常接近我记得的,虽然我的原始设置是〜5年前在Gentoo盒子上) 。 If I recall correctly, you should find the username in the $_SERVER["REMOTE_USER"] variable in this setup. 如果我没记错的话,您应该在此设置中的$_SERVER["REMOTE_USER"]变量中找到用户名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM