PHP LDAP 连接
我正在尝试使用 php-ldap 连接 LDAP。我在使用 ldap_bind() 时遇到问题:
$username = 'josue.ruiz';
$password = 'pass';
$ldapconfig['host'] = '10.10.10.11';
$ldapconfig['port'] = 389;
$ldapconfig['basedn'] = 'dc=domain,dc=com';
$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$dn="cn=".$username.",ou=Technology,".$ldapconfig['basedn'];
if ($bind=ldap_bind($ds, $dn, $password)) {
echo("Login correct");
} else {
echo("Login incorrect");
}
我收到以下消息:
警告:ldap_bind():无法绑定到服务器:...中的凭据无效
但是当我尝试这种方式时:
ldap_bind($ds,'[email protected]','pass');
它工作正常,但对我来说它不起作用,因为我想按OU,用这种方式我不能。有人对这个问题有什么建议吗?
I'm trying to connect in LDAP with php-ldap. I got a issue using ldap_bind()
:
$username = 'josue.ruiz';
$password = 'pass';
$ldapconfig['host'] = '10.10.10.11';
$ldapconfig['port'] = 389;
$ldapconfig['basedn'] = 'dc=domain,dc=com';
$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$dn="cn=".$username.",ou=Technology,".$ldapconfig['basedn'];
if ($bind=ldap_bind($ds, $dn, $password)) {
echo("Login correct");
} else {
echo("Login incorrect");
}
I get this message:
Warning: ldap_bind(): Unable to bind to server: Invalid credentials in ...
But when I try this way:
ldap_bind($ds,'[email protected]','pass');
It works fine, but to me it doesn't work because I want to filter by OU
, and with this way I can't. Does anyone have any advice for this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您尝试执行 ldap_bind 时,您只是进行连接并确定凭据是否有效。您需要做的是将您的域名添加到用户名中并让它连接。然后,如果您想使用 ldap_search() 确定用户是否是“技术”OU,请考虑这样做:
When you are trying to do
ldap_bind
you are only connecting and determining if the credentials validate. What you need to do is add your domain to the username and let it connect. Then if you want to determine if the user is the 'Technology' OU withldap_search()
Consider doing it like this: