Shakir Blouch
Shakir Blouch

Reputation: 187

ldap_bind(): Unable to bind to server: Invalid DN syntax

I am trying to get authentication from ldap and I am geting the error "ldap_bind(): Unable to bind to server: Invalid credentials" any one can provider any information about this .

Below the code I use:

$ldaphost = "ldap.mydomain.com"; $ldapport = 389; 
$ds = ldap_connect($ldaphost, $ldapport) or die("Could not connect to $ldaphost"); 
if ($ds) { 
   $username = "myUser"; 
   $upasswd = "*****"; 
   $binddn = "uid=$username,ou=people,dc=yourdomain,dc=com"; $ldapbind = ldap_bind($ds, $binddn, $upasswd); 
if ($ldapbind) { echo "login" ; } else { echo " not login"; } 
}

Upvotes: 2

Views: 7238

Answers (1)

Yash Malla
Yash Malla

Reputation: 366

$ldaphost = "ldap.mydomain.com"; 
$ldapport = 389; 

$ds = ldap_connect($ldaphost, $ldapport) or die("Could not connect to $ldaphost"); 
if ($ds) { 
 $username = "myUser"; 
 $upasswd = "*****"; 
 $binddn = "cn=admin,dc=yourdomain,dc=com"; //cn=admin or whatever you use to login by phpldapadmin
 $ldapbind = ldap_bind($ds,$binddn, $upasswd); 

 //check if ldap was sucessfull 
 if ($ldapbind) {
    echo "LDAP bind successful...";
 } else {
    echo "LDAP bind failed...";
 }
}

Upvotes: 2

Related Questions