Skip to content

Getting FullName from Active Directory in Php

To get the full name of any user from Active directory use the below code

$userId=trim($userId);
exec("NET USER /DOMAIN ".$userId." 2>1",$output);
$fullName=$output[3];
$userID=$output[2];
$fullName=trim(preg_replace("#Full Name#","",$fullName));
	

Incase you want to display the full name of the user who is currently visiting from your page which is hosted on IIS then use the code below

$user = $_SERVER['AUTH_USER'];
$domain = getenv('USERDOMAIN');
$users=explode("\\",$user);
$userID=$users[1];
exec("NET USER /DOMAIN ".$userId." 2>1",$output);
$fullName=$output[3];
$userID=$output[2];
$fullName=trim(preg_replace("#Full Name#","",$fullName));