尝试绑定无效凭据时出错

时间:2014-08-28 15:36:17

标签: php ldap

我正在尝试连接到LDAP服务器,但我总是在尝试绑定时出错:无效凭据'当我提供正确的凭据时。如何解决此问题?我怎么知道连接是否成功?我被困在这里请告诉我是否有任何建议。

    <?php
    $domain = 'school123.edu';
    $username = 'test';
    $password = 'password';
    $ldapconfig['host'] = 'server123';
    $ldapconfig['port'] = 389;

    $ldapconn=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

        // binding to ldap server
        $ldapbind = ldap_bind($ldapconn, $username, $password) or die ("Error trying to bind: ".ldap_error($ldapconn));
        // verify binding
        if ($ldapbind) {
            echo "LDAP bind successful...<br /><br />";

     } else {
            echo "LDAP bind failed...";
        }

     $dn='dc=school123,dc=edu';
     $result = ldap_search($ldapbind,$dn,'(&(objectClass=*)(sAMAccountName=' . $username. '))');

    $entries = ldap_get_entries($ldapconn, $result);
    echo $entries["count"]." entries returned\n";

    // all done? clean up
    ldap_close($ldapconn);
    ?>

0 个答案:

没有答案