Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you get a Windows (AD) username in PHP?

I have a PHP web application on an intranet that can extract the IP and host name of the current user on that page, but I was wondering if there is a way to get/extract their Active Directory/Windows username as well. Is this possible?

like image 438
fuentesjr Avatar asked Oct 03 '08 19:10

fuentesjr


People also ask

What is Active Directory username?

Active Directory (AD) is a service run by CITES to manage usernames and passwords. Your AD username is the same as your netID. If you are a Windows user, it is the same username and password that you currently use to log into your desktop.

What is a ad login?

Active Directory (AD) is more than just a repository of IDs and passwords; it's the center of just about every bit of security in your network. Going beyond the rudimentary managing of permissions, AD establishes policies and controls over what privileges accounts have, and how those account can be used.


2 Answers

Check the AUTH_USER request variable. This will be empty if your web app allows anonymous access, but if your server's using basic or Windows integrated authentication, it will contain the username of the authenticated user.

In an Active Directory domain, if your clients are running Internet Explorer and your web server/filesystem permissions are configured properly, IE will silently submit their domain credentials to your server and AUTH_USER will be MYDOMAIN\user.name without the users having to explicitly log in to your web app.

like image 89
Dylan Beattie Avatar answered Sep 23 '22 08:09

Dylan Beattie


I've got php mysql running on IIS - I can use $_SERVER["AUTH_USER"] if I turn on Windows Authentication in IIS -> Authentication and turn off Anonymous authentication (important)

I've used this to get my user and domain:

$user = $_SERVER['AUTH_USER']; 

$user will return a value like: DOMAIN\username on our network, and then it's just a case of removing the DOMAIN\ from the string.

This has worked in IE, FF, Chrome, Safari (tested) so far.

like image 20
Schwarz.Oz Avatar answered Sep 23 '22 08:09

Schwarz.Oz