doushang1880 2015-03-10 08:30
浏览 88
已采纳

如果我需要在LDAP和PHP中搜索两个子文件夹,我可以为$ base_dn添加什么

I only have a very basic understanding of doing LDAP searches. I'm using PHP with Laravel.

I'm trying to do a search for all users within my my OU=USERS directory. I have two subfolders within that: OU=STAFF and OU="STUDENTS. I want to be able to search for a specific DN by username within both of those directories. The problem is that I can only make my search work if I specify either the STAFF or STUDENTS directories. I currently have:

...
$base_dn = 'OU=USERS,DC=mysite,DC=mydomain,DC=edu';
$filter = "(&(objectClass=person)(sAMAccountName=$username))";

$result = ldap_search($connection, $base_dn, $filter);
$entries = ldap_get_entries($connection, $result);


foreach ($entries as $entry) {
    $ldapUsername = $entry["sAMAccountName"][0];
    echo $ldapUsername;
    return;
}

It will work if I specify either

$base_dn = 'OU=STAFF,OU=MMM_USERS,DC=mmc,DC=mmm,DC=edu';

or

$base_dn = 'OU=STUDENTS,OU=MMM_USERS,DC=mmc,DC=mmm,DC=edu';

but not without them.

Overall, I'm just trying to validate a user based off of their username, which is also their cn, and their LDAP password. As far as I've been able to tell, however, I need to first get their DN, to try to bind to the connection with the DN and password, taken from a PHP form input.

Any advice on the specifics or the overall method of going about this would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • douyanqu9722 2015-03-11 02:44
    关注

    Depending on your LDAP Server Implementation you could use an extensible matching filter.

    However, I suspect you are using Microsoft Active Directory and it does NOT support extensible matching as you wish to perform.

    -jim

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部