PHP LDAP Connection(PHP LDAP 连接)
问题描述
我正在尝试使用 php-ldap 在 LDAP 中进行连接.我在使用 ldap_bind()
时遇到问题:
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");
}
我收到这条消息:
警告:ldap_bind():无法绑定到服务器:凭据无效...
Warning: ldap_bind(): Unable to bind to server: Invalid credentials in ...
但是当我尝试这种方式时:
But when I try this way:
ldap_bind($ds,'josue.ruiz@domain.com','pass');
它工作正常,但对我来说它不起作用,因为我想按 OU
过滤,而这种方式我不能.有人对这个问题有什么建议吗?
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?
推荐答案
当您尝试执行 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 with ldap_search()
Consider doing it like this:
$domain = 'mydomain.com';
$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="ou=Technology,".$ldapconfig['basedn'];
$bind=ldap_bind($ds, $username .'@' .$domain, $password);
$isITuser = ldap_search($bind,$dn,'(&(objectClass=User)(sAMAccountName=' . $username. '))');
if ($isITuser) {
echo("Login correct");
} else {
echo("Login incorrect");
}
这篇关于PHP LDAP 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP LDAP 连接
基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01