0
votes

Through LDAP I am trying to get te e-mail adresses of all users in a group. Below is the code I've got and I can't get it to work. The error I get is: Bad search filter.

if ($ldapconn) {
    echo "jep";
    echo "<br />";

    $basedn = "DC=lab,DC=kuhlmann-its,DC=local";
    $classname = "TAI2";
    $filter = "(&(objectClass=user)(memberOf=OU=TAI2,OU=Accounts,OU=BBS_Students,OU=BBS,OU=EDUNET))";
    $attributes = array("givenName", "sn", "mail");
    $search = ldap_search($ldapconn, $filter, $attributes);
    $info = ldap_get_entries($ldapconn, $search);

}

This is my first time working with LDAP and Active Directory and I don't know how all the functions work. I want to know why my ldap_search() is not working.

Thanks in advance.

1

1 Answers

0
votes

I have noticed that sequence of parameters is incorrect.

$search = ldap_search($ldapconn, $filter, $attributes);

If you check official documentation, you will notice that above line should be

$search = ldap_search($ldapconn, $basedn, $filter, $attributes);

Refer ldap_search on official php.net documentation.