diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index 9b76c34da1f..295554b2d93 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -358,7 +358,10 @@ class Ldap dol_syslog(get_class($this)."::connectBind serverPing true, we try ldap_connect to ".$host, LOG_DEBUG); } if (version_compare(PHP_VERSION, '8.3.0', '>=')) { - $uri = $host.':'.$this->serverPort; + // Since PHP 8.3, ldap_connect() expects a single URI argument. A scheme-less + // host (ex: localhost, 192.168.0.2) must be turned into a valid ldap:// URI, + // otherwise the host is parsed as the URI scheme and the later bind fails. + $uri = preg_match('/^ldaps?:\/\//i', $host) ? $host : 'ldap://'.$host.':'.$this->serverPort; $this->connection = ldap_connect($uri); } else { $this->connection = ldap_connect($host, $this->serverPort); @@ -371,7 +374,7 @@ class Ldap dol_syslog(get_class($this)."::connectBind serverPing false, we try ldap_connect to ".$host, LOG_DEBUG); } if (version_compare(PHP_VERSION, '8.3.0', '>=')) { - $uri = $host.':'.$this->serverPort; + $uri = preg_match('/^ldaps?:\/\//i', $host) ? $host : 'ldap://'.$host.':'.$this->serverPort; $this->connection = ldap_connect($uri); } else { $this->connection = ldap_connect($host, $this->serverPort);