LDAP DN语法用法
问题描述:
这是我原来的语法:LDAP DN语法用法
$dn = "OU=Users,OU=NA1,DC=corp,DC=pvt";
我想多一个OU添加到$dn
。
目录结构如下。 OU=NA1
,在NA1下有两个活动目录:用户和联系人
所以,我想在下面的单行中调用两个活动目录。 (注意:这个语法不起作用)
$dn = "OU=Users+Contacts,OU=NA1,DC=corp,DC=pvt";
有什么办法可以在一行中添加两个活动目录吗?
答
对于读取操作,PHP支持称为并行搜索的功能。这并不像你想要的那么简单,但是你可以在一次操作中获得你想要的结果。
$links = array($link, $link); // yes, two references to the same link
$DNs = array(
'OU=Users,OU=NA1,DC=corp,DC=pvt',
'OU=Contacts,OU=NA1,DC=corp,DC=pvt'
);
$filter = 'attr=val';
// a regular call to ldap_search()
// only now, $results is and array of result identifiers
$results = ldap_search($links, $DNs, $filter);
你可以用这个进入功能,这将使通话更加简单,像:
function ldap_multi_search($link, array $dns, $filter, array $attributes = null, $attrsonly = null, $sizelimit = null, $timelimit = null, $deref = null)
{
$dns = array_values($dns);
$links = array_fill(0, count($dns), $link);
$results = ldap_search($links, $dns, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref);
$retVal = array();
foreach ($results as $i => $result) {
if ($result === false) {
trigger_error('LDAP search operation returned error for DN ' . $dns[$i], E_USER_WARNING);
continue;
}
$entries = ldap_get_entries($result);
unset($result['count']); // we'll calculate this properly at the end
$retVal = array_merge($retVal, array_values($entries));
}
$entries['count'] = count($entries);
return $entries;
}
你想进行什么操作,搜索? – DaveRandom