Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php ldap_搜索中按特定OU进行过滤?_Php_Ldap - Fatal编程技术网

如何在php ldap_搜索中按特定OU进行过滤?

如何在php ldap_搜索中按特定OU进行过滤?,php,ldap,Php,Ldap,我正在尝试在我正在编写的LDAP实用程序类中编写一个方法。我希望它能找到特定OU中的所有用户。OU恰好是OU=用户 此版本的代码将获取所有人员。我想进一步过滤它 public function find_all_users(){ $rv = array(); $filter = '(&(ObjectCategory=person)(SAMAccountName=*))'; // <-- this finds all person objects $wa

我正在尝试在我正在编写的LDAP实用程序类中编写一个方法。我希望它能找到特定OU中的所有用户。OU恰好是OU=用户

此版本的代码将获取所有人员。我想进一步过滤它

public function find_all_users(){
    $rv = array();

    $filter = '(&(ObjectCategory=person)(SAMAccountName=*))';   // <-- this finds all person objects
    $wanted_attribute = array("dn");

      // Search for the attribute in the domain
        if ( ! $result_ldap_search = ldap_search($this->connection, $this->base_dn, $filter, $wanted_attribute) ) {
            throw new \Exception("Could not search LDAP. " . ldap_error($this->connection) );
        }
        else {
      // Process LDAP search results
            $rv[] = ldap_get_entries($this->connection, $result_ldap_search);

        }

    return $rv;
}

但当我运行它时,它什么也找不到,没有返回任何记录。可能是因为用户OU中没有对象吗?我们所有的用户都在多个OU中。我想找到那些在OU=Users中的用户,但是在另一个OU中也可以。是否存在忽略所有其他OU的特殊语法?

是OU=Users还是CN=Users?这实际上是一个用户的属性吗?
$filter = '(&(ObjectCategory=person)(SAMAccountName=*)(OU=Users))';