首页 > 解决方案 > LDAP 连接适用于 PHP 5 但不适用于 PHP 7

问题描述

我想绑定到 LDAP 服务器,但是当我尝试在 PHP 7 中这样做时,它不起作用。然而,相同的代码在 PHP 5 中有效。

我有代码:

$ldapconn = ldap_connect("ldaps://192.168.22.222:636")
or die("Could not connect to LDAP server.");

if ($ldapconn) {
    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);

    $ldapbind = ldap_bind($ldapconn, 'username', 'password');
    if ($ldapbind) {
        echo "LDAP bind successful...";
    } else {
        echo "LDAP bind failed...";
    }
}

当我在 PHP 5 中执行此代码时,我得到:

LDAP bind successful...

在 LDAP 服务器日志中,我可以看到:

conn=434976 fd=26 ACCEPT from IP=8.8.8.8:43536 (IP=0.0.0.0:636)
conn=434976 fd=26 TLS established tls_ssf=128 ssf=128
conn=434976 op=0 BIND dn="" method=128
conn=434976 op=0 RESULT tag=97 err=0 text=
conn=434976 op=1 UNBIND
conn=434976 fd=26 closed

在 PHP 7 中,我得到响应:

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

在 LDAP 日志中:

conn=434975 fd=26 ACCEPT from IP=8.8.8.8:50919 (IP=0.0.0.0:636)
conn=434975 fd=26 TLS established tls_ssf=256 ssf=256
conn=434975 fd=26 closed (connection lost)

我找到了一些在 LDAP 服务器上禁用证书验证的解决方案,但我无法更改该服务器的配置中的任何内容。

你能帮我如何在 PHP 7 中绑定吗?我在 PHP 7.2 和 7.3 中使用默认配置进行了测试。

标签: phpldap

解决方案


推荐阅读