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.