ldap_bind():无法绑定到服务器:无效的DN语法

时间:2014-02-07 13:15:50

标签: php ldap

我正在尝试从ldap获取身份验证,而我正在查找错误 “ ldap_bind():无法绑定到服务器:凭据无效” 任何人都可以提供任何有关此事的信息。

在我使用的代码下面:

$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"; } 
}

1 个答案:

答案 0 :(得分:2)

$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...";
 }
}