|
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 ]
| 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. | ||


