LDAP 服务器应由主机访问


ldap server should be reached by the hosting

当我测试时ldap_bind它在我的测试机器上工作,因为它与我的 LDAP 服务器位于同一域中,但是当我将代码移动到虚拟主机时

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in /home 

我正在从与ldap服务器位于同一域中的浏览器访问它,那么LDAP服务器应该由主机访问吗?

            <?php
            // using ldap bind
            $ldaprdn  = 'user';     // ldap rdn or dn
            $ldappass = 'pass';  // associated password
            // connect to ldap server
            $ldapconn = ldap_connect("server.com")    or die("Could not connect to LDAP server.");
            if ($ldapconn) {
                // binding to ldap server
                $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
                // verify binding
                if ($ldapbind & strlen($ldappass)>0) {
                   echo "H LDAP bind successful...";
                } else {
                    echo "LDAP bind failed...";
                }
            }
            ?>

我这边有几个检查点:

  • 似乎您正在使用LDAPS,即通过SSL,因此请确保证书位于Web托管环境中主机的信任库中。
  • 如果您使用主机名而不是IP,则可以尝试以下操作:$ip = gethostbyname('ldap.example.com');$ldapconn = ldap_connect($ip);

  • 还要检查LDAP端口是否不是默认端口,如果不是默认端口,您可以指定。

简单的 BIND 操作需要一个 DN,而不仅仅是 DN 的一个组件。