2012-07-05 24 views
1

在命令行上运行ldapsearch命令时,它会返回大量结果,而通过PHP进行的等效(或我认为)查询不会返回任何结果。PHP ldap_search()和CLI ldapsearch返回不同的结果

ldapsearch命令:

ldapsearch -Zx -H ldap://directory.host.ca -D [CREDENTIALS] -w [PASSWORD] -z 0 -l 0 - LLL -b "ou=people,dc=business,dc=ca" "(&(facultyCode=AU)(term="1380")" uid 

PHP搜索:

//binding has already happened with the same credentials as used in the CLI command 
$filter = '(&(facultyCode=AU)(term="1380"))'; 
$list = ldap_search($conn,'ou=people,dc=business,dc=ca',$filter,array('uid'),0,0,0); 

我缺少什么?

回答

0

检查服务器日志以确定在搜索请求中传输的内容。这两个例子中的过滤器可能不相同。例如,PHP可能会将"字符转换为'(单引号至双引号)。在编码过滤器中,'"不等效。

此外,使用ldapsearch壳示例将不编码term="1380",而是term=1380,这是不一样的term="1380"。换句话说,ldapsearch命令是(一些壳可能逃过不同引号的字符串):

ldapsearch -Zx -H ldap://directory.host.ca \ 
    -D [CREDENTIALS] -w [PASSWORD] -z 0 -l 0 \ 
    -LLL -b "ou=people,dc=business,dc=ca" \ 
    '(&(facultyCode=AU)(term=1380)' uid 
+0

我没有对服务器的访问日志,但我会玩的报价和看能不能让他们匹配。谢谢。 – Pickle 2012-07-06 14:10:24

+0

单引号,双引号,无引号 - CLI命令始终有效。单引号,双引号,双引号编码为\ 22 - 总是通过PHP返回0个结果。删除引号超时。 – Pickle 2012-07-06 14:54:26

+0

'term'属性值是否有双引号,编码或其他? – 2012-07-06 16:20:42