#native_company# #native_desc#

Create an LDAP Address Book

By Dannie Stanley
on February 6, 2001


This article will attempt to demonstrate how to connect to an LDAP server
using PHP. Specifically, the example given will connect
to a public LDAP server and perform searches. This example closely
mimics the way Netscape?? Communicator 4.* uses its address book to
connect to LDAP resources.

Introduction to LDAP

Many have probably heard much about LDAP, but have no idea what it
is or how it works. I will not attempt to teach everything there is
to know about LDAP, but here is a brief description of the protocol.
LDAP is a protocol for distributing directory information to many different
resources. Most commonly it is used as a centralized address book, but it can
be much more powerful depending on an organization’s needs.
LDAP in its most basic form is a standard way to connect to a database. The
database is optimized for read queries. Thus, it retrieves information very
quickly, in contrast to additions or updates which are slower. It is important to
note that LDAP most often uses a hierarchal database, rather than a
relational database to store data. Therefore, the structure is better represented with a tree
than a table. As a result, SQL syntax will be rendered unusable.
In short, LDAP is a fast way to retrieve centralized, static data containing information
about people and/or resources.


  • PHP v.4 (previous versions may work but are untested) compiled with
    support for LDAP, I.E. –with-ldap.
  • Publically accessible LDAP directory. Two are provided in the example.


Overview of Example

  1. Setup Public LDAP Server Information
  2. Create LDAP Query
  3. Connect to LDAP Server
  4. Process Query if Connection Was Successful
  5. Format Output
  6. Close Connection
  7. Make HTML Form for Search Interface
  8. Echo Results


Setup Public LDAP Server Information

The first thing we need to do is define all of the LDAP servers we might
want to search.

The name of the new LDAP entry.
The IP address or hostname of the new LDAP entry.
The root distinguished name of the new LDAP entry.


$LDAP_NAME[0]           = "Netscape Net Center";

$LDAP_SERVER[0]         = "memberdir.netscape.com";

$LDAP_ROOT_DN[0]        = "ou=member_directory,o=netcenter.com";

$LDAP_NAME[1]           = "Bigfoot";

$LDAP_SERVER[1]         = "ldap.bigfoot.com";

$LDAP_ROOT_DN[1]        = "";

//If no server chosen set it to 0