|
Create an LDAP Address Book
Dannie Stanley
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
- Setup Public LDAP Server Information
- Create LDAP Query
- Connect to LDAP Server
- Process Query if Connection Was Successful
- Format Output
- Close Connection
- Make HTML Form for Search Interface
- 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;
?>
| Comments: | ||
| RE: Problems with jpegs | fips | 11/13/02 08:19 |
| Warning: Undefined offset: ............. | Matthew | 09/30/02 05:54 |
| LDAP referral | Chalapathi Rao | 08/28/02 08:06 |
| LDAP in Exchange. | colin | 08/05/02 17:18 |
| is there a script for centralized addressbook | Md. Matiur Rahman Siddiqui | 07/15/02 08:22 |
| how to bind ldap server | thippeswamy | 07/10/02 10:13 |
| Need Help | proavis | 06/09/02 16:30 |
| PROBLEM!! Searching... | Sorin Marti | 04/09/02 10:50 |
| Char set for Latin1 | Andreas | 03/27/02 07:26 |
| Address Book on Netscape | Alfred Weiss | 03/20/02 20:15 |
| ldaps | Jacob | 02/25/02 18:21 |
| RE: ldap_modify failed | bubuf | 01/21/02 02:12 |
| RE: ldap_connect() is not found | Speed Expert | 12/11/01 09:45 |
| Help about certificate in ldap | jordan_xiao | 12/11/01 02:36 |
| how to import SQL data in to LDAP | mahesh | 12/07/01 08:39 |
| RE: ldap_connect() is not found | Jai | 11/27/01 07:57 |
| Undefined Functions | roger | 11/27/01 00:31 |
| ldap_modify failed | apropos | 11/15/01 02:34 |
| ldap_modify failed | binaural | 11/15/01 00:36 |
| RE: ldap_connect() is not found | Lee | 10/24/01 13:04 |
| Thanks! | Andy | 10/23/01 06:56 |
| I can't connect LDAP | Benjamas | 09/23/01 23:53 |
| RE: ldap_connect() is not found | Mike Fox | 09/18/01 17:45 |
| ldap_connect() is not found | Dan | 09/10/01 09:04 |
| I am not getting connection | Riyaz | 07/26/01 22:13 |
| I am not getting connection | Riyaz | 07/26/01 22:11 |
| install mail server with ldap address book | debo | 07/16/01 01:59 |
| RE: Problems with jpegs | Falk Sauer | 07/08/01 03:37 |
| help | daya | 07/03/01 19:59 |
| SEARCHING | saumya bhuayn | 06/25/01 21:07 |
| upgradation of php 3.xx version to php 4.x | I. Satya Sekhar Trainee IISc | 05/17/01 22:12 |
| RE: Problems with jpegs | Billy Davis | 05/17/01 13:01 |
| Have I forgotten something to install ? | Frankie | 03/23/01 09:29 |
| RE: example | Daniell Freed | 03/02/01 08:15 |
| Problems with jpegs | raz | 02/09/01 08:37 |
| Problems with jpegs | raz | 02/09/01 08:37 |
| "PublicPIM" | James M. Orr | 02/08/01 10:12 |
| example | Alta Ergo | 02/07/01 11:12 |
| Difference between a directory and a database | Kevin Monroe | 02/07/01 09:02 |
| Array index | Jose' L Landivar | 02/06/01 11:50 |
| Array index | Jose' L Landivar | 02/06/01 11:50 |
| error in code | Pedro Reis | 02/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. | ||


