简体   繁体   中英

PHP problems with LDAP search

I am new to using PHP with active directory and LDAP. I want to retrieve a users full name, and then display it on a page. I gone to PHP's website to read up on the ldap syntax. I am having problems the ldap_search. I get the following error messages:

Warning: ldap_search(): Search: Operations error in C:\\inetpub\\wwwroot\\notes\\ldap_conn2.php on line 18

$host = "x.x.x.x";
$port = "389";

$conn = ldap_connect($host, $port) or die ("Connected to LDAP Server!");

$bind = ldap_bind($conn) or die ("LDAP Bind successful!");

$dn = "ou=department, dn=company, dn=domain";
$filter = "(sAMAccountName=" . $user . ")";
$att = array("cn", "displayName", "givenName", "sn", "mail");
$r = ldap_search($conn, $dn, $filter, $att);

ldap_unbind($conn);

Your code looks fine, assuming the "host" you're connecting to is actually running Active Directory.

AD is not installed by default in Windows. To run an AD server, you need to add the Active Directory Domain Services role (assuming Windows 2008+).

I saw the problem for the search, "dn=" should be "dc=". Everything worked after that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM