adam
adam

Reputation: 2970

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. All of our users are on IE. We do use AD for our usernames inside our company network.

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.

Is there a way (through LDAP or other means) of getting the logged on windows username? 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. But again, this is a very last resort.

The link here: Can you get a Windows (AD) username in PHP? 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.

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.

Upvotes: 4

Views: 7038

Answers (2)

Michael Payne
Michael Payne

Reputation: 544

You can get it from an ActiveX object and JavaScript since you're using IE. To get this into PHP, maybe include it as a hidden field in a login page?

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.

Upvotes: 3

WWW
WWW

Reputation: 9860

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). If I recall correctly, you should find the username in the $_SERVER["REMOTE_USER"] variable in this setup.

Upvotes: 0

Related Questions