php - 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 中使用默认配置进行了测试。
解决方案
推荐阅读
- ms-media-foundation - AMDh264Encoder 在检查 MFSampleExtension_CleanPoint 时返回 MF_E_ATTRIBUTENOTFOUND
- python - 最快获取通知信息的方法
- python - 无法在机器上安装 rudderstack
- css - 如何在两侧均匀地添加 Bootstrap 5 填充?
- python - 如何使用 Python 计算时间加权平均值?
- javascript - 无法使用 React Native Expo 导入 Firebase JS SDK
- python - 脚本在到达某一行时退出并给出错误代码 -1073740791
- xml - 使用 XSL 将复杂的 XML 转换为简化的 XML
- react-native - 运行 Jest 测试套件时无法从 npm 包中找到模块
- pine-script - 松脚本代码,停止盈亏平衡。但想不通