尝试获取用户数据时,LDAP上的搜索过滤器过滤

Car*_*tes 7 php ldap ldap-query symfony-1.4

我在这里使用LDAP开箱即用,所以如果我以完全错误的方式做这件事,请告诉我.

我正在使用bhLDAPAuthPlugin插件使用Symfony 1.4

我正在验证用户使用LDAP登录.但是,我希望使用用户名查询LDAP表中的更多数据.所以我写这个搜索功能来根据用户名过滤结果:

function user_values($username) {
if (!$username) {
    die ("Username is not there man!");
}

if (!$this->_conn) {
    die ("No Connection.");
}
if (!$this->_base_dn) {
    die ("No Base.");
}
$filter="samaccountname=".$username;

$attributes_ad = array("name");
$result = ldap_search($this->_conn, $this->_base_dn, $filter, $attributes_ad) 
or die ("Error in search query");
$entries = ldap_get_entries($this->_conn, $result);
    return($entries);
}
Run Code Online (Sandbox Code Playgroud)

我收到错误:

警告:ldap_search():搜索:错误的搜索过滤器/ ...搜索查询错误

当我运行查询.

前三个"if"是为了确保我获得了正确的搜索参数.实际搜索条件失败.

有什么建议?

UPDATE

用户名变量是jtesting

在将它放入搜索参数之前,我从函数中提取了$ username.它实际上是(jtesting).我将删除括号,看看是否可以解决问题.

Ter*_*ner 7

为了在过滤器的断言值中使用括号,必须对括号进行转义.断言值所在的搜索过滤器samAccountName=(jtesting)应编码为samAccountName=\28jtesting\29.整个断言值可以包含在未转义的括号中,在这种情况下,过滤器变为(samAccountName=\28jtesting\29).

更多信息