In the first part of this article, I had written a simple PHP script to search the LDAP directory for a particular user. But real life is never that simple... Let's suppose I want to search for my friend Joe from high school. Now, there are a million Joes in the world, and I would like to drill down to my Joe without having to navigate through a large set of results. The solution? A more complex search, which uses additional parameters to restrict the result set. Take a look at the new search form, which looks like this: ![]() Once the form above is submitted, the data entered by the user is sent to the search script "search.php", which actually performs the query - take a look: The structure of the code is identical to that of the examples in previous pages - with one important difference: This search string, obviously with the variables replaced with actual values, is passed to the ldap_search() function; it returns only those entries from the LDAP directory free which match *all* the parameters specified. Why? Because of my usage of the special AND operator, signified by the addition of the ampersand (&) to the beginning of the search string above. Here's what the output looks like: ![]() If your LDAP entries contain other attributes, it's just as easy to create more complex search queries - simply add more input fields to the search form, and update the search string above to use those attributes when searching the directory tree. In case you were wondering, yes, you can also use logical OR (the | operator) or logical NOT (the ! operator) in your search queries - I'll leave that to you to play with.
blog comments powered by Disqus |