LDAP连接在PHP 5上运行但不在PHP 7上运行

我想绑定到LDAP服务器,但是当我尝试在PHP 7中执行此操作时,它无法正常工作。 然而,相同的代码在PHP 5中有效。</ p>

我有代码:</ p>

  $ ldapconn =  ldap_connect( “LDAPS://192.168.22.222:636”)\也不死亡( “无法连接到LDAP服务器。”); 

如果($ 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绑定失败...“;
}
}
</ code> </ pre>

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

  LDAP绑定成功... 
</ code> </ pre>

在LDAP服务器日志中,我可以看到:</ p>

   conn = 434976 fd = 26接受来自IP = 8.8.8.8:43536(IP = 0.0.0.0:636)
nconn = 434976 fd = 26 TLS建立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
</ code> </ pre> \ n

在PHP 7中,我得到了回复:</ p>

 警告:ldap  _bind():无法绑定到服务器:无法联系LDAP服务器
</ code> </ pre>

和LDAP日志中:</ p>

 < 代码> conn = 434975 fd = 26接受来自IP = 8.8.8.8:50919(IP = 0.0.0.0:636)
nconn = 434975 fd = 26 TLS建立tls_ssf = 256 ssf = 256
conn = 434975 fd = 26已关闭( 连接丢失)
</ code> </ pre>

我发现了一些在LDAP服务器上禁用证书验证的解决方案,但我无法更改该服务器配置中的任何内容。</ p>
\ 你能帮我解决如何在PHP 7中绑定的问题吗? 我在PHP 7.2和7.3中使用默认配置进行了测试。</ p>
</ div>

展开原文

原文

I want to bind to LDAP server, but when I try to do that in PHP 7 it is not working. Same code however works in PHP 5.

I have code:

$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...";
    }
}

When I execute this code in PHP 5 I get:

LDAP bind successful...

And in LDAP server logs I can see this:

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

In PHP 7 I get response:

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

and in LDAP logs:

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)

I found some solutions with disabling cert validation on LDAP server, but I cannot change anything in config of that server.

Can you help me how to bind in PHP 7? I tested that in PHP 7.2 and 7.3 with default config.

duanou8504
duanou8504 您是否在此Web服务器上安装了适当的SSL证书,以便将LDAPS与LDAP/AD主机一起使用?
一年多之前 回复
drl37530
drl37530 是的,我有--with-openssl配置php。在php5我也有sslv3,但我不确定这是否可能是问题
一年多之前 回复
duanjianxu4288
duanjianxu4288 ldaps意味着您正在尝试进行安全连接。你在PHP7版本中有openssl扩展吗?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问