【问题标题】:LDAP Connector stops working when using INI config instead of PHP arrayLDAP 连接器在使用 INI 配置而不是 PHP 数组时停止工作
【发布时间】:2026-01-22 02:15:01
【问题描述】:

我有这个功能:

<?php
private function spawnAdapter($credentials) {

    //$ldapConfig = array("server1" => array(
    //  "host" => "172.16.100.32",
    //  "useStartTls" => 1,
    //  "accountDomainName" => "schoolxp",
    //  "accountDomainNameShort" => "schoolxp",
    //  "accountCanonicalForm" => 3,
    //  "baseDn" => "DC=schoolxp",
    //));

    // We must retrieve the LDAP servers from the conf
    $ldapConfig = $this->_config->ldap->toArray();

    // Remove the log path, otherwise the adapter will think this is
    // one of our servers and fail.
    unset($ldapConfig['log']);   

    $adapter = new Zend_Auth_Adapter_Ldap(
        $ldapConfig, 
        $credentials['username'], 
        $credentials['password']
    );

    return $adapter;

}
?>

还有一个如下所示的ini配置文件:

[production]
ldap.log.enabled = 1
ldap.log.path = "../logs/ldap.log"
; Place your Active Directory Server Settings Here.
ldap.server1.host = "172.16.100.32"
ldap.server1.useStartTls = 1
ldap.server1.accountDomainName = "schoolxp"
ldap.server1.accountDomainNameShort = "schoolxp"
ldap.server1.accountCanonicalForm = 3
ldap.server1.baseDn = "DC=schoolxp"

当 PHP 数组用于 Auth_Adapter 时,代码运行良好,但是如果我切换到使用 INI 配置,它会失败并出现未知错误。

我在 INI 文件数组和 PHP 数组上都运行了 print_f,它们是相同的,但是 LDAP 适配器仍然在日志文件中引发异常。

有趣的是,日志中的连接字符串对于 INI 文件和数组是相同的。对于感兴趣的人,这里是日志文件:http://pastebin.com/V5Nyz9FK

任何有关情况的信息将不胜感激

【问题讨论】:

    标签: zend-framework ldap ini


    【解决方案1】:

    在我看来,LDAP 适配器尝试连接到错误的端口 (0)。 请尝试使用:

    ldap.server1.port = 389
    

    或您正在使用的任何端口。

    【讨论】:

    • 尝试添加 389 和 636(基于 SSL/TLS 的 LDAP)但这仍然不起作用 - 尝试连接时我仍然收到“未知错误代码”错误。
    • 您的 AD 服务器上是否有有效证书(自签名证书无效)?如果没有,您可能想先尝试不使用 TLS 进行连接。
    • 成功了!它没有解释为什么在 ini 文件中设置它不起作用,因为基本上 LDAP 适配器接收完全相同(或者我认为)的数组,无论使用哪个配置,并且它在使用原生 PHP 数组时有效相同的设置
    • @BradMorris 那你不介意接受我的回答吗? :)
    • 虽然这解决了问题,但它并没有真正回答我的问题——为什么会发生这种情况?两个数组本质上是相同的,为什么一个有效而另一个无效?