首页 > 解决方案 > CodeIgniter - “ldap_bind():无法绑定到服务器:无法联系 LDAP 服务器”来自 localhost

问题描述

我必须使用 CodeIgniter 3 处理用 PHP 5.5 编写的旧应用程序。

对于身份验证,它使用 ldap 连接到具有 Auth_AD 库的私有服务器。

在生产服务器和测试服务器中,此 ldap 连接成功,但是当我尝试从本地主机内进行身份验证时,我收到此错误

A PHP Error was encountered

Severity: Warning

Message: ldap_bind(): Unable to bind to server: Can't contact LDAP server

Filename: libraries/Auth_AD.php

Line Number: 388

凭据在任何地方都完全相同。

这是在第 388 行调用的函数(第一次 ldap_bind() 调用):

private function bind_ad()
    {
      // preset the continuation marker
        $continue = true;

        // attempt to connect to each of the AD servers, stop if a connection is succesful
        foreach ($this->_hosts as $host) {
            $this->_ldap_conn = ldap_connect($host);
            if ($this->_ldap_conn) {
                break;
            } else {
                log_message('info', 'Auth_AD: Error connecting to AD server ' . $host);
            }
        }

        // check for an active LDAP connection
        if (!$this->_ldap_conn) {
            log_message('error', "Auth_AD: unable to connect to any AD servers.");
            show_error('Error connecting to any Active Directory server(s). Please check your configuration and connections.');
            $continue = false;
        }

        if ($continue) {
            // set some required LDAP options
            ldap_set_option($this->_ldap_conn, LDAP_OPT_REFERRALS, 0);
            ldap_set_option($this->_ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);

            // attempt to bind to the AD using the proxy user or anonymously if no user was configured
            if ($this->_proxy_user != null) {
                ldap_bind($this->_ldap_conn, $this->_proxy_user, $this->_proxy_pass);
            } else {
                $bind = ldap_bind($this->_ldap_conn);
            }

            // verify the LDAP binding
            if (!$bind) {
                if ($this->_proxy_user != null) {
                    log_message('error', 'Auth_AD: Unable to perform LDAP bind using user ' . $this->_proxy_user);
                    show_error('Unable to bind (i.e. login) to the AD for user ID lookup');
                } else {
                    log_message('error', 'Auth_AD: Unable to perform anonymous LDAP bind.');
                    show_error('Unable to bind (i.e. login) to the AD for user ID lookup');
                }

                $continue = false;
            } else {
                log_message('debug', 'Auth_AD: Successfully bound to AD. Performing DN lookup for user');
            }
        }

        // return the result
        return $continue;
    }

我认为这不是代码问题,因为代码库在 localhost 或生产环境中是相同的,可以正常工作。任何想法 ?

标签: phpcodeigniterldap

解决方案


推荐阅读