Webmaster (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume

Create an LDAP Address Book
Introduction
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.
Requirements
  • 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.
LDAP_NAME
The name of the new LDAP entry.
LDAP_SERVER
The IP address or hostname of the new LDAP entry.
LDAP_ROOT_DN
The root distinguished name of the new LDAP entry.

<?php

$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
if(!$SERVER_ID)
  
$SERVER_ID=0;
  
?>
[ Next Page ]


Comments:
RE: Problems with jpegsfips11/13/02 08:19
Warning: Undefined offset: .............Matthew09/30/02 05:54
LDAP referralChalapathi Rao08/28/02 08:06
LDAP in Exchange.colin08/05/02 17:18
is there a script for centralized addressbookMd. Matiur Rahman Siddiqui07/15/02 08:22
how to bind ldap serverthippeswamy07/10/02 10:13
Need Helpproavis06/09/02 16:30
PROBLEM!! Searching...Sorin Marti04/09/02 10:50
Char set for Latin1Andreas03/27/02 07:26
Address Book on NetscapeAlfred Weiss03/20/02 20:15
ldapsJacob02/25/02 18:21
RE: ldap_modify failedbubuf01/21/02 02:12
RE: ldap_connect() is not foundSpeed Expert12/11/01 09:45
Help about certificate in ldapjordan_xiao12/11/01 02:36
how to import SQL data in to LDAP mahesh12/07/01 08:39
RE: ldap_connect() is not foundJai11/27/01 07:57
Undefined Functionsroger11/27/01 00:31
ldap_modify failedapropos11/15/01 02:34
ldap_modify failedbinaural11/15/01 00:36
RE: ldap_connect() is not foundLee10/24/01 13:04
Thanks!Andy10/23/01 06:56
I can't connect LDAPBenjamas09/23/01 23:53
RE: ldap_connect() is not foundMike Fox09/18/01 17:45
ldap_connect() is not foundDan09/10/01 09:04
I am not getting connectionRiyaz07/26/01 22:13
I am not getting connectionRiyaz07/26/01 22:11
install mail server with ldap address bookdebo07/16/01 01:59
RE: Problems with jpegsFalk Sauer07/08/01 03:37
help daya07/03/01 19:59
SEARCHINGsaumya bhuayn06/25/01 21:07
upgradation of php 3.xx version to php 4.x I. Satya Sekhar Trainee IISc05/17/01 22:12
RE: Problems with jpegsBilly Davis05/17/01 13:01
Have I forgotten something to install ?Frankie03/23/01 09:29
RE: exampleDaniell Freed03/02/01 08:15
Problems with jpegsraz02/09/01 08:37
Problems with jpegsraz02/09/01 08:37
"PublicPIM"James M. Orr02/08/01 10:12
exampleAlta Ergo02/07/01 11:12
Difference between a directory and a databaseKevin Monroe02/07/01 09:02
Array indexJose' L Landivar02/06/01 11:50
Array indexJose' L Landivar02/06/01 11:50
error in codePedro Reis02/06/01 08:21
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.