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.
Diego, what the var returns if it does
var_dump($value)
? For the record, the@
there is no need, I believe.– Guilherme Nascimento
The
sAMAccountName
would the login? try$attributes = array('name', 'sAMAccountName');
– rray
@Guilhermenascimento, you’re right, the @ was there to hide the error.
– Diego
@rray this there, put $Attributes = array('sAMAccountName'); and returned the user. Want to post as answer.... thank you!!!
– Diego