在某些情况下,ldap_get_entries返回元素count = 0的数组,所以我有一个数组,如array('count'=> 0),没有任何进一步的条目。
这种情况有什么条件?
PS:
编辑:
$entries = ldap_get_entries($this->ldap_connection, $search_result);
所以,重述一下我的问题,ldap_get_entries返回一个count = 0的数组有什么条件,没有任何错误。按条件我的意思是:
由于
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
}
答案 0 :(得分:1)
这意味着您搜索的内容未返回结果,因为它不存在或您没有正确搜索结果。
答案 1 :(得分:1)
似乎ldap_connect
已成功连接到您的服务器。
我认为问题在于来自ldap_base_distinguished_name
的{{1}}参数,请确保它是正确的,并且您在AD树中具有该基本专有名称。
答案 2 :(得分:0)
$ldap = new stdclass;
$ldap->host = 'YOUR_HOST';
$ldap->port = 'PORT';
$ldap->user = 'YOUR_USER';
$ldap->pass = 'YOUR_PASS';
$ldap->dn = "CN=Users,DC=DOMAIN,DC=COM,DC=br";
$ldap->filter = '(sAMAccountName=YOUR_USER_NAME)';
try {
$ldap->conn = ldap_connect($ldap->host,$ldap->port);
$ldap->bind = ldap_bind($ldap->conn, $ldap->user, $ldap->pass);
$ldap->option[] = ldap_set_option($ldap->conn, LDAP_OPT_PROTOCOL_VERSION,3);
$ldap->option[] = ldap_set_option($ldap->conn, LDAP_OPT_REFERRALS,0);
$ldap->seach=ldap_search($ldap->conn, $ldap->dn, $ldap->filter);
$ldap->info = ldap_get_entries($ldap->conn, $ldap->seach);
var_dump($ldap);
} catch (Exception $error_message) {
throw new RuntimeErrorException($error_message);
}