PHP Return AD user

Asked

Viewed 705 times

3

I have the query below, which searches the full name of the registered AD 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 the people who start with Helmet.

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

inserir a descrição da imagem aqui

  • Diego, what the var returns if it does var_dump($value)? For the record, the @ there is no need, I believe.

  • 1

    The sAMAccountName would the login? try $attributes = array('name', 'sAMAccountName');

  • @Guilhermenascimento, you’re right, the @ was there to hide the error.

  • @rray this there, put $Attributes = array('sAMAccountName'); and returned the user. Want to post as answer.... thank you!!!

1 answer

4


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

$attributes = array('name', 'sAMAccountName');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.