
October 26th, 2009, 07:18 AM
|
|
Contributing User
|
|
Join Date: Feb 2001
Posts: 130
Time spent in forums: 25 m 5 sec
Reputation Power: 9
|
|
|
Search Errors with PHP/LDAP on Active Directory
Hi all,
I'm trying to get started with LDAP/Active Directory and I can't seem to get a proper search result. I either get 0 entries, or I get too many entries. Here is the output of my script:
Code:
Active Directory Test
Connect result is: Resource id #2
LDAP bind successful...
Warning: ldap_search() [function.ldap-search]: Partial search results returned: Sizelimit exceeded in /home/statik/web_root/index.php on line 33
Search result is Resource id #3
----
Resource id #3
----
entries returned
and here is the code, thus far:
PHP Code:
<?php
$ldaphost = "cai.dnd";
$ldapport = "3268";
$ldapconn = ldap_connect( $ldaphost )
or die( "Could not connect to ($ldaphost)" );
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
echo "Connect result is: ".$ldapconn."<br />";
$ldapuser = "admin";
$ldappass = "*********"; //yes, I replaced the password. :)
if ($ldapconn) {
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);
if ($ldapbind) {
echo "LDAP bind successful...<br />";
} else {
echo "LDAP bind failed...<br />";
}
}
$dn = "dc=cai,dc=dnd";
$filter = "(cn=*)";
$attributes = array("username", "mail");
$searchresult = ldap_search($ldapconn, $dn, $filter, $attributes, 0, 20)
or die ("Error is search query");
echo "Search result is ".$searchresult."<br />";
echo "<br />----<br /><pre>";
print_r($searchresult);
echo "</pre>----<br />";
$info = ldap_get_entries($ldapconn, $searchresult);
echo $info["Count"]." entries returned\n";
ldap_close($ldapconn);
?>
What am I doing wrong?
Thanks,
Statik
|