I am trying to get information out of AD using LDAP query and PHP. Below is my code and it seems like nothing returns from this code. I have an issue with code block in if (TRUE === $bind). Would anyone help me to point out the error?
This is php code for listing all users in AD and showing up on WordPress page.
$ldap_password = "pass";
$ldap_username = "username";
$person = "Scott";
$ldap_connection = ldap_connect("host1");
if (FALSE === $ldap_connection) {
echo "Connection is failed<br />";
}
else {
echo "Connection is successful<br />";
}
ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die("Unable to set LDAP protocol version");
ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0);
$bind = ldap_bind($ldap_connection, $ldap_username, $ldap_password);
if (TRUE === $bind) {echo "Binding is successful<br />";}
else {echo "Binding is unsuccessful<br />";}
if (TRUE === $bind) {
echo "Retrieving...<br />";
$baseDN = "dc=domain,dc=com";
$filter="(|(sn=$person*)(givenname=$person*))";
$justthese = array("ou");
$sr = ldap_list($ldap_connection, $baseDN, $filter, $justhese);
$info = ldap_get_entries($ldap_connection,$sr);
echo $info["count"]."Hello<br />";
for ($i=0; $i < $info["count"]; $i++) {
echo $info[$i]["ou"][0];
}
ldap_unbind($ldap_connection);
echo "Unbinding is completed<br />";
}
This is what shows up on the page
Connection is successful
Binding is successful
Retrieving…
Hello
Unbinding is completed
Thanks