Querying in AD (Active Directory) with PHP

1

I currently have in the environment the AD (Active Directory) of Windows Server 2012. Now in my PHP application I can already connect to this AD via ldap_connect + ldap_bind .

However, I would like to make a query within AD. Search for example the field displayName, mail or any attribute contained in the Attribute Editor tab.

I already found the PHP manual ldap_search , but I was unable to get it to work properly. Not to mention I do not know if this function would be the correct one for me.

Thank you.

EDIT-- Date: 04/27/2015.

I was able to perform the query, see how my code was:

$filtro = "(&(objectClass=user)(objectCategory=person)(displayname=*)(sAMAccountname=$login1))";
$mostrar = array("samaccountname");
if (!($busca=@ldap_search($connect, $base_dn, $filtro, $mostrar))){
    die("Não foi possível realizar busca no Active Directory");
}
$info = ldap_get_entries($connect, $busca);
echo "<pre>".print_r($info,true)."</pre>";exit;
    
asked by anonymous 24.04.2015 / 20:31

1 answer

1

I was able to perform the query, see how my code was:

$filtro = "(&(objectClass=user)(objectCategory=person)(displayname=*)(sAMAccountname=$login1))";
$mostrar = array("samaccountname");
if (!($busca=@ldap_search($connect, $base_dn, $filtro, $mostrar))){
    die("Não foi possível realizar busca no Active Directory");
}
$info = ldap_get_entries($connect, $busca);
echo "<pre>".print_r($info,true)."</pre>";exit;
    
05.09.2015 / 23:04