Source for file search_entries.php
Documentation is available at search_entries.php
* This is a short example on how to search for entries in your
* directory using Net_LDAP.
// We use the connecting.php example to get a link to our server.
// This file will also include all required basic Net_LDAP classes.
include_once 'connecting.php';
// Okay, we should have a valid link now.
// We must now define a filter that defines, which
// entries we want to have returned.
// We use the Net_LDAP_Filter class for this purpose,
// because so we don't need to worry about
// In this example, we want all users with first names
// starting with "bened" and the last names ending with "ger".
// Additionally, we want to exclude all users with names
// containing "smith", which will be done throug a "negation".
// Building and negating the "no smith" filter component
// this must be done in two steps, because
// you are able to negate EVERY filter, not just leave filters.
// the $filter_smith will not be used afterwards and is only
// necessary for negation here.
// Now combine all filter components to build our search filter
// The filter is ready now, so we can
// use this filter now to search for entries.
// The scope we use is "sub", meaning "all entries below the search base".
// The base is "null", meaning the base defined in $ldap_config. This is similar
// to call $ldap->search($ldap_config['base'], ...
$requested_attributes = array ('sn','gn','telephonenumber');
$search = $ldap->search (null , $filter, array ('attributes' => $requested_attributes));
die ('LDAP search failed: '. $search->getMessage ());
// Lets see what entries we got and print the names and telephone numbers:
if ($search->count() > 0 ) {
echo "Found ". $search->count(). ' entries:<br>';
// Note, this is is only one of several ways to fetch entries!
// You can also retrieve all entries in an array with
// $entries = $search->entries()
// or the same thing sorted:
// $entries = $search->sorted()
while ($entry = $search->shiftEntry ()) {
$surename = $entry->getValue ('sn', 'single');
die ('Unable to get surename: '. $surename->getMessage ());
$givenname = $entry->getValue ('gn', 'single');
die ('Unable to get givenname: '. $givenname->getMessage ());
$phone = $entry->getValue ('telephonenumber', 'single');
die ('Unable to get phone number: '. $phone->getMessage ());
echo " <br>$givenname $surename: $phone";
die ('Sorry, no entries found!');
Documentation generated on Mon, 11 Mar 2019 15:32:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|