<?php
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
if (isset($_SERVER['HOME']) && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$ldaprcfile = $_SERVER['HOME'] . '/.ldaprc';
if (!file_exists($ldaprcfile)) {
@file_put_contents($ldaprcfile, 'TLS_REQCERT allow')
}
putenv('LDAPCONF=' . $ldaprcfile);
}
putenv('LDAPTLS_REQCERT=allow');
putenv('TLS_REQCERT=allow');
$hostPrefix = 'ldaps://my.ldap.server';
$port = 636;
ldap_set_option(null, LDAP_OPT_NETWORK_TIMEOUT, 5);
$l = ldap_connect($hostPrefix, $port);
if (!$l) {
echo "Connect to $hostPrefix:$port failed!";
}
ldap_set_option($l, LDAP_OPT_NETWORK_TIMEOUT, 5);
ldap_set_option($l, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($l, LDAP_OPT_REFERRALS, 0);
$bind_dn = 'xxxxx';
$b = ldap_bind($l, $bind_dn, 'xxxxx');
if (!$b && ldap_errno($l) === -1) { // -1 = No TCP connection
echo "Connect try #$connTry failed!";
}
if (!$b) {
echo 'Bind failed! ' . ldap_error($l) . ' - Errno: ' . ldap_errno($l);
}
3
$result = ldap_search($l, 'dc=ldap', '(mail=*me*)', ['mail'], 0, -1, -1, LDAP_DEREF_NEVER);
$entries = ldap_get_entries($l, $result);
PHP Warning: ldap_connect(): Could not create new security context in /root/ldap_test.php on line 35
PHP 8.4.21 (cli) (built: May 14 2026 16:00:34) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.4.21, Copyright (c) Zend Technologies
with Zend OPcache v8.4.21, Copyright (c), by Zend Technologies
with Xdebug v3.5.0, Copyright (c) 2002-2025, by Derick Rethans
Description
The following code:
Resulted in this output:
But I expected this output instead:
Maybe this is a known bug, following up from #18529 ?
Only 8.4 is not working:
PHP Version
Operating System
Ubuntu 22.04