PHP LDAP连接 [英] PHP LDAP Connection

查看:303
本文介绍了PHP LDAP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在LDAP与PHP-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");
}

我得到这个消息:

I get this message:

警告:的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'); 

它工作正常,但对我来说这是行不通的,因为我想通过过滤,并用这种方式,我不能。有没有人有任何意见,对于这个问题?

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()考虑做这样的:

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连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆