4

I'm creating a LDAP directory search using PHP and we're using Novell as our LDAP server. I'm able to successfully search and return results; this is the current filter I'm running, (&(FERPA=N)(|(uid=*searchphrase*)(sn=*searchphrase*)(fullName=*searchphrase*)(telephoneNumber=*searchphrase*))).

I want to be able to sort by last name, or the LDAP variable sn. I could sort it via PHP, but I want that to be the last resort. Is there a way to sort the results based on a column. For example, in SQL you can sort based on a column like this, SELECT * FROM TABLE WHERE COL='criteria' ORDER BY COL; Is there something similar that can be done with LDAP Queries?

samwell
  • 2,757
  • 9
  • 33
  • 48
  • 1
    Just wondering if you know about this ldap_sort function(http://www.php.net/manual/en/function.ldap-sort.php). – Neal Apr 10 '12 at 09:45
  • I've looked into it, but I wasn't able to find documentation for that specific function. Plus, I'm trying to sort the results via LDAP Queries, if I can't figure out a way to do it via LDAP Queries, then I will resort to sorting via PHP. – samwell Apr 11 '12 at 19:06

2 Answers2

3

LDAP client applications that require results of search requests to be ordered in a repeatable way should use the server-side sort extension. In most cases, use of the server-side sort extension requires the application coder to inform the directory administrators so that proper indexing can be setup.

Community
  • 1
  • 1
Terry Gardner
  • 10,957
  • 2
  • 28
  • 38
  • SOrry I might be missing something, but how does this help my question about sorting LDAP Results via LDAP Queries? – samwell Apr 11 '12 at 19:06
  • It doesn't. It's not the simple paged results but the [server-side sort extension](http://tools.ietf.org/html/rfc2891). Sorry for the confusion. – Terry Gardner Apr 11 '12 at 19:10
0

As far as I know there is no way to sort results with a LDAP filter. All a filter does is limit what entries are returned.

With php, you would run your search, then sort the result with http://us3.php.net/manual/en/function.ldap-sort.php

Alternatively, you could read all the entries into an array and then run one of php's other sorting functions on them. http://us1.php.net/manual/en/array.sorting.php

David R.
  • 518
  • 2
  • 9
  • 20