PHP Return AD user

3

I have the following query, which searches for the full name of the AD registered user:

<?php

//Conexao com AD
$ldapconfig['host']= '192.168.203.99'; //AD-001
$ldapconfig['port']= '389'; //Porta Padrão
$ldapconfig['dn'] = "";
$domain= 'peccin.local';
$username = 'diego.venuzka';
$password = 'xxxxxxx';

//Faz conexão com AD usando LDAP
$sn= ldap_connect($ldapconfig['host'], $ldapconfig['port']);
ldap_set_option($sn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($sn, LDAP_OPT_REFERRALS, 0);

@$bind=ldap_bind($sn, $username .'@'.$domain, $password);


$filter = "(sAMAccountName=carlo*)";
$attributes = array('name');
$search = ldap_search($sn,'DC=peccin, DC=local', $filter, $attributes);

$data = ldap_get_entries($sn, $search);

foreach ($data AS $key => $value){

echo @$value["name"][0]."<br>";

}

?>

In this case it returns the full name of people who start with carlo .

Is there any way I can get the User Logon Name field below? I tried user, username, logonname, login but I could not.

    
asked by anonymous 11.04.2018 / 16:42

1 answer

4

The sAMAccountName is the login, so to recover it put this field in the selection of the returned attributes.

$attributes = array('name', 'sAMAccountName');
    
11.04.2018 / 19:14