Lord OfTheRing
Lord OfTheRing

Reputation: 1299

ldap_bind(): Unable to bind to server

I have below code and I am getting error:

Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in C:\xampp\htdocs\ldap.php on line 17

<?php
$ldapconfig['host'] = "dsua1.company.com";
$ldapconfig['port'] = 636;
$ldapconfig['basedn'] = "cn=userid,ou=Applications,ou=Company,ou=Services,dc=iM-2,dc=com";
$ldapconfig['binddn'] = "userid";
$ldapconfig['bindpw'] = "password";
$ldapconn=ldap_connect($ldapconfig['host'],$ldapconfig['port']);

ldap_bind($ldapconn, $ldapconfig['binddn'], $ldapconfig['bindpw']);
?>

Upvotes: 2

Views: 6640

Answers (1)

Ctx
Ctx

Reputation: 18410

Since you specified port 636, I assume that you need an SSL-connection to the server. This is achieved by:

ldap_connect("ldaps://".$ldapconfig['host']."/");

Otherwise it would try to send plaintext data which would not be accepted on an SSL-socket.

Furthermore, try this after ldap_connect() and before ldap_bind():

ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);

Sometimes an error occurs when an incorrect protocol version is used, 3 is common now, but not standard for the ldap_* PHP function family.

Upvotes: 6

Related Questions