Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Create an LDAP Address Book
Create LDAP Query
As mentioned previously, LDAP queries are not much like SQL queries. Therefore, the syntax may seem a bit limiting, but here is a basic example and one that works in this scenario.
//Create Query
$ldap_query = "cn=$common";
In our example "cn" is the attribute on which we are performing the search, and $common is the search string variable from the search form. LDAP query syntax allows for wildcard matching using '*'. For example, '*stanley' will find 'dan stanley'.
Connect to LDAP Server
The given function connects to an LDAP resource and assigns the connection link identifier to a variable, much like connecting to a regular database, like MySQL.

<?php

//Connect to LDAP
$connect_id = ldap_connect($LDAP_SERVER[$SERVER_ID]);

?>
In our example, "$connect_id" is the link identifier, $LDAP_SERVER is the array of possible ldap servers, and $SERVER_ID is the LDAP server variable from the search form.
Process Query if Connection Was Successful
If our connection was successful, we will have a valid LDAP link identifier and we can process the query.

<?php

if($connect_id)
  {
  
//Authenticate
  
$bind_id = ldap_bind($connect_id);
  
  
//Perform Search
  
$search_id = ldap_search($connect_id, $LDAP_ROOT_DN[$SERVER_ID], $ldap_query);
  
  
//Assign Result Set to an Array
  
$result_array = ldap_get_entries($connect_id, $search_id);
  }
else
  {
  
//Echo Connection Error
  
echo "Could not connect to LDAP server: $LDAP_SERVER[$SERVER_ID]";
  }
  
?>
Once we have established a connection to the LDAP services, we must identify ourselves. Most database connections with PHP send the username and password with the connection. However, with LDAP, credentials are unknown until a bind is performed. In our example, "$bind_id" is the bind link identifier. We are performing an anonymous bind to the public LDAP servers. Therefore, no argument is sent to ldap_bind() accept the connection link identifier.
After we have been authorized, via bind as anonymous, we perform the query using the ldap_search() function. $search_id is created and is our search link identifier.
Then, we assign our result set to the variable $result_array using the function ldap_get_entries(). This will allow us to sort the information in a logical manner for display.
[ Next Page ]

[Page 1]  [Page 2]  


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.