【发布时间】:2011-04-12 15:03:04
【问题描述】:
在某些情况下,ldap_get_entries 返回元素计数为零的数组,因此我有一个类似 array('count'=>0) 的数组,没有任何其他条目。
发生这种情况的条件是什么?
PS:
- 如果我正在搜索的 OU 为空,我会收到另一个错误(无效的 Base DN)
- 如果用户没有 OU 的权限,我会遇到与上述相同的错误
编辑:
- PHP 代码无关紧要,因为我可以用它进行各种搜索,而上述问题只发生在一些奇怪的 Active Directory 配置中
- 如果你还坚持...
$entries = ldap_get_entries($this->ldap_connection, $search_result); - ldap_get_entries 在大多数情况下返回我期望它返回的正确错误
所以,重申一下我的问题,ldap_get_entries 返回 count=0 且没有任何错误的数组的条件是什么。我的意思是:
- Active Directory 权限和权限
- 用户权限
- OU 权限(又名安全选项卡)
- 有关何时发生这种情况的任何 PHP 相关信息
谢谢
EDIT2 - 根据要求,以下是其余代码:
public function connect() {
// connect to the server
$this->ldap_connection = ldap_connect($this->ldap_server);
if (!$this->ldap_connection){
$error_message= "LDAP-Connect-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
// set protocol version
if (!ldap_set_option($this->ldap_connection, LDAP_OPT_PROTOCOL_VERSION, $this->ldap_protocol_version)){
$error_message= "LDAP-SetProtocolVersion-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
// set with/without referrals (limit/do not limit search on current server)
if (!ldap_set_option($this->ldap_connection, LDAP_OPT_REFERRALS, $this->ldap_protocol_referrals)){
$error_message= "LDAP-SetReferrals-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
// binding to ldap server
if (!@ldap_bind($this->ldap_connection, $this->ldap_auth_rdn, $this->ldap_auth_pass)){
$error_message= "LDAP-Bind-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
}
public function search($filter,$fields){
if (!$this->ldap_connection) {
$this->connect();
}
// search the ldap
$search_result = @ldap_search($this->ldap_connection, $this->ldap_base_distinguished_name, $filter,$fields);
if ($search_result===false){
$error_message= "LDAP-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
//Create result set
$entries = ldap_get_entries($this->ldap_connection, $search_result);
if ($entries === false ){
$error_message= "LDAP-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
return (is_null($entries) ? array() : $entries); // http://bugs.php.net/48469
}
【问题讨论】:
-
您的 PHP 代码是相关的。我们不知道您是如何设置连接的。例如,您需要在 PHP 代码中设置 AD 的某些选项。
标签: php ldap ldap-query