March 22nd, 2010, 01:37 PM
-
PHP - Trying to search the AD without sucess
Hello,
I'm new using LDAP with PHP.
I can connect to the server. But I'm trying to look for users at AD without sucess.
My users are not in Users folders. They're organized as follows:
"DC=dc01,DC=com";
The list of users are only inside NORMAL.
I'm trying an anonymous users, but even if try to connect via bind, I have no sucess trying to bind.
That's the php code:
$dn = "DC=dc01,DC=com,OU=CITY,OU=USERS,OU=NORMAL";
$conexao = ldap_connect("ldap://ip_server", 389) or die("Couldn't connect to AD!");
if (!$conexao) {
echo "Problemas ao Conectar";
exit;
}
$bind = ldap_bind($conexao);
if (!$bind) {
echo "Problemas ao fazer o bind";
}
$result = ldap_search($conexao, $dn, "cn=*");
$entries = ldap_get_entries($conexao, $result);
echo "O numero eh: " . $entries["count"];
for ($i=0; $i<$entries["count"]; $i++)
{
echo $entries[$i]["displayname"]
[0]."(".$entries[$i]["l"][0].")<br />";
}
ldap_unbind($bind);
March 24th, 2010, 06:49 PM
-
First AD does not support anonymous BINDs unless explicitly setup to do so.
Second, the DN you have is incorrect
$dn = "DC=dc01,DC=com,OU=CITY,OU=USERS,OU=NORMAL";
should be
$dn = "OU=NORMAL,OU=USERS,OU=CITY,DC=dc01,DC=com";