Quasipickle
Quasipickle

Reputation: 4498

PHP ldap_search() and CLI ldapsearch return different results

When running an ldapsearch command on the command line, it returns tons of results, whereas an equivalent (or so I think) query via PHP returns nothing.

ldapsearch command:

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 search:

//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);

What am I missing?

Upvotes: 1

Views: 1039

Answers (1)

Terry Gardner
Terry Gardner

Reputation: 11132

Check the server logs to determine what was transmitted in the search request. The filters may not be equivalent in the two examples. For example, PHP might convert the " characters to ' (single-quote to double-quote). Inside an encoded filter, ' and " are not equivalent.

Also, the shell example using ldapsearch would not encode term="1380", but rather term=1380, which is not the same as term="1380". In other words, the ldapsearch command is (some shells may escape quoted strings differently):

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

Upvotes: 0

Related Questions