In addition, instead of the flat structure provided by a database, an
LDAP server allows you to organize people in a hierarchical fashion.
For example, employees may be divided into marketing, technical, and
operations divisions, or they can be split regionally into North
America, Europe, and Asia. This makes it easy to find all employees
of a particular subset of a company.
ldap_bind($ds, $username, $password) or die($php_errormsg);
Once logged in, you can request information. Because the information
is arranged in a hierarchy, you need to indicate the base
distinguished name as the second parameter. Finally, you pass in the
search criteria. For example, here's how to find all
people with a surname of Jones at company
Example Inc. located in the country
US:
$sr = ldap_search($ds, 'o=Example Inc., c=US', 'sn=Jones') or die($php_errormsg);
$e = ldap_get_entries($ds, $sr) or die($php_errormsg);