脚本宝典收集整理的这篇文章主要介绍了php – LDAP问题,ldap_bind无效的dn语法,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图用PHP创建一个函数,所以我可以连接到LDAP并找到所需的信息.
$ldapconfig['host'] = "127.0.0.1"; $ldapconfig['port'] = NULL; $ldapconfig['basedn'] = "dc=example,dc=com"; $ldapconfig['binddn'] = "user"; $ldapconfig['bindpw'] = "password"; function ldap_authenticate($user,$pass) { global $ldapconfig; ldap_set_option(NULL,LDAP_OPT_DEBUG_LEVEL,7); if ($user != "" && $pass != "") { $ds=ldap_connect($ldapconfig['host'],$ldapconfig['port']); if(!ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3)) { return NULL; } ldap_set_option($ds,LDAP_OPT_REFERRALS,0); ldap_bind( $ds,$ldapconfig['binddn'],$ldapconfig['bindpw']); $r = ldap_seArch( $ds,$ldapconfig['basedn'],'sAMAccountName=' . $user); if ($r) { $result = ldap_get_entries( $ds,$r); if ($result[0]) { if (ldap_bind( $ds,$result[0]['dn'],$pass) ) { return $result[0]['mail'][0]; } } } } return NULL;
当我尝试运行代码时,它给了我以下错误:
ldap_bind xxxx行上的DN语法无效
那行是以下内容:
ldap_bind( $ds,$ldapconfig['bindpw']);
“cn = username,ou = domain users,dc = example,dc = com”
根据您的LDAP(Active Directory,OPEnLDAP等)的风格,您可能可以使用uid(所以只是’用户名’)进行绑定,但最好假设您始终需要完整的DN.
您可以使用像Apache Directory Studio这样的LDAP工具来帮助构建@L_777_25@并找出对象的DN.或者也有ldp.exe(如果是AD),但目录工作室更容易使用.
以上是脚本宝典为你收集整理的php – LDAP问题,ldap_bind无效的dn语法全部内容,希望文章能够帮你解决php – LDAP问题,ldap_bind无效的dn语法所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。