面临警告LDAP使用PHP错误链接资源


Facing Warnings LDAP using PHP wrong link resource

我正试图通过php中的LDAP连接到active directory。但我收到以下警告:

  • 警告:ldap_search((:在第39行的C:''Program Files(x86(''EasyHP-12.1''www''GuestRegister''login.php中,提供的参数不是有效的ldap链接资源

  • 警告:ldap_get_entries((要求参数1为资源,字符串在C:''Program Files(x86(''EasyHP-12.1''www''GuestRegister''login.php第41行中给出条目返回

有人能帮忙吗?:(

我的代码看起来像:

  <?php
    $ds = "10.33.85.172";
    $ldaprdn  = "CN=HackTeam,CN=Users,DC=cisco,DC=internal";    
    $ldappass = 'HackMe007';
    // connect to ldap server
    $ldapconn = ldap_connect("10.33.85.172")
    or die("Could not connect to LDAP server.");
    if ($ldapconn) {
    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
    // verify binding
    if ($ldapbind) {
        echo "Connected to LDAP";
        ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
        ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);
        $filter="(|(sn=guest-Juan*)(givenname=Juan*))";
        $justthese = array("ou", "sn", "givenname", "mail");
        $sr=ldap_search($ds, $ldaprdn, $filter, $justthese);
        $info = ldap_get_entries($ds, $sr);
        echo $info["count"]." entries returned'n";
    } else {
        echo "Connection to LDAP Failed";
    }
}       
?>

更改:

$sr=ldap_search($ds, $ldaprdn, $filter, $justthese);

$sr=ldap_search($ldapconn, $ldaprdn, $filter, $justthese);

应该将connection resource作为第一个参数传递给ldap_search,传递的是$ds,它只是一个带有ldap服务器ip的字符串。