Using the LDAP Function in PHP
The ldap_get_dn function gets the distinguished name from an entry in the result of a search. It needs the result_entry_identifier, an LDAP link identifier returned by ldap_connect.
The LDAP protocol works with "Directory Servers," which organize information in a structure that is similar to the hard disk directory structure (with forward slashes marking each division). In the top level of this tree, you find entries for people. In lower levels, you find entries for organisations or places. In still lower levels, you find entries for equipment or documents. Each entry has attributes, which are values such as names or addresses.
In PHP, you can work on entries or attributes a bit at a time by using the ldap_get_entries and ldap_get_attributes functions. These functions return multidimensional arrays of the results of a search, where each dimension holds the values for a given attribute. You can also get a list of all the attribute values for a single entry by calling ldap_get_values or ldap_get_values_len.
Before you can use the ldap_get_dn and other LDAP functions, you must have a working connection to an LDAP server. You can get a copy of the University of Michigan ldap-3.3 package or the Netscape Directory SDK and recompile your PHP installation with LDAP support enabled. The Netscape SDK includes a helpful Programmer's Guide in HTML format. Also, you'll need to understand LDAP concepts such as scopes, scope variables and naming contexts. The article, Understanding LDAP, provides a primer on these topics.