|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-06-13 06:01 UTC] benoit at gide dot net
Compiled modules:
./configure --with-apache=../apache_1.3.24 --with-openssl --with-ldap
I have a problem when i use php to bind my ldap directory over ssl
If i use on shell command
ldapsearch -x -H 'ldaps://localhost/' -b 'uid=100000, ou=company, dc=domain, dc=com' -D 'uid=100000, ou=company, dc=mydomain, dc=com' -W
I have good result
My script is like that :
$server = "ldap://localhost" ;
$ds=ldap_connect($server);
$dn = "uid=100000, ou=company, dc=domain, dc=com";
$value = "password";
$result=@ldap_bind($ds,$dn,$value);
$dn = "ou=company, dc=domain, dc=com";
$filtre = "(cn=*DUPONT*)";
$sr = ldap_search($ds, $dn, $filtre);
$info = ldap_get_entries($ds, $sr);
for ($i=0; $i < $info["count"]; $i++) {
print "UID: ".$info[$i]["urn"][0]."<br /><br />";
}
ldap_close($ds);
i have a result, but if i change $server = "ldap://localhost" by "ldaps://localhost) i have a error message "Can't contact LDAP server"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 18:00:01 2025 UTC |
This error not only happens with SSL (ldaps), but also when using StartTLS. On my system, the correct CA certificate is referenced in /etc/ldap/ldap.conf and command line utilities can connect without problems: ~# ldapsearch -v -x -ZZ "(objectClass=*)" ldap_initialize( <DEFAULT> ) filter: (objectClass=*) requesting: ALL # extended LDIF # ... But the following PHP script fails (on PHP-5.1.2 from Ubuntu-6.06): <?php $server = ldap_connect("ldap://ldap.example.com"); ldap_set_option($server, LDAP_OPT_PROTOCOL_VERSION, 3); $result = ldap_read($server, "dc=example,dc=com", "(objectclass=*)"); $entry = ldap_get_entries($server, $result); print_r($entry); // everything works fine up to this point // no network problems, we are really talking to the server ldap_start_tls($server); // this fails: // Warning: ldap_start_tls() [function.ldap-start-tls]: // Unable to start TLS: Connect error in /var/www/ldaptest.php on line 10 ldap_close($server); ?> As you can see a "Connect error" is returned, altough this seems to be an error while checking the server certificate. I can get the command line utilities to throw the same error by making the CA certificate unreadable: ~# ldapsearch -v -x -ZZ "(objectClass=*)" ldap_initialize( <DEFAULT> ) ldap_start_tls: Connect error (-11) The PHP script will work, if I disable the verification of the server certificate by putting the already mentioned "TLS_REQCERT never" in /etc/ldap/ldap.conf