A Sample LDAP Application in PHP Page 14
February 22, 2002
So we finally get down to putting to some practical purpose what
we gleaned through the course of this chapter.
We will develop an application that will export the directory
information for the employees of our favorite company Foo Widgets
Inc. Let us look at what could be the possible requirements and
design considerations for such an application:
- There are two categories of users - regular employees and the
directory administrator.
- The application should allow a regular employee to search
entries corresponding to all other employees and to modify the
entry corresponding to them.
- The administrator should have exclusive priveleges
unavailable to regular employees - to create new entries and
delete existing entries.
- The application should use an LDAP directory as the back-end.
- It should have a simple front-end, with all complexity moved
to the back-end. It should ideally be browser-independent.
- A set of common utility functions first, upon which to build
the application itself.
The script below is the first that gets invoked as part of
launching the application:
<?php
// empdir_first.php
We include a set of utility functions here:
require("empdir_functions.php");
This script is called again as a result of the user deciding to
either add a new entry or to search for an existing entry:
if (!isset($choice)) {
generateHTMLHeader("Click below to access the Directory");
generateFrontPage();
} else if (strstr($choice, "ADD")) {
$firstCallToAdd = 1;
For additions to the directory the empdir_add.php script is
called:
require("empdir_add.php");
} else {
$firstCallToSearch = 1;
For searching the directory, we call the empdir_search.php
script:
require("empdir_search.php");
}
?>
This is how the initial screen would look to the user:
The script empdir_common.php contains some site-specific
information that we need to customize to suit over environment:
<?php
//empdir_common.php
This conditional statement would ensure that this file does not
get included multiple times:
//Avoid multiple include()
if (isset($EMPDIR_CMN)) {
return;
} else {
$EMPDIR_CMN = true;
}
//Customize these to your environment
This is the base DN of our company directory:
$baseDN = "o=Foo Widgets, c=us";
Below is the fully qualified hostname and port number of the LDAP
server. We use OpenLDAP in this case - however, the code should
work fine with any standard LDAP server:
$ldapServer = "www.foowid.com";
$ldapServerPort = 4321;
?>
Professional PHP4 Programming
A Sample LDAP Application in PHP Page 15
|