这是我的原始语法:
$dn = "OU=Users,OU=NA1,DC=corp,DC=pvt";我想再向$dn添加一个OU。
目录结构如下所示。
OU=NA1,在NA1下有两个活动目录: Users和Contacts
因此,我想在单行中调用这两个活动目录,如下所示。(注意:此语法不起作用)
$dn = "OU=Users+Contacts,OU=NA1,DC=corp,DC=pvt"; 有没有办法在一行中同时添加两个活动目录?
发布于 2013-07-19 22:51:57
对于读操作,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;
}https://stackoverflow.com/questions/17748513
复制相似问题