Using PHP to connect to an LDAP server

Source: Internet
Author: User
Tags html form ldap
This article demonstrates how to use PHP to connect to an LDAP server. A specific example is to connect to a common LDAP server and search. This example simulates the Netscape Communicator 4.*, which connects to the LDAP resource through its own address book.
 
LDAP Introduction
Many people may have heard of LDAP, but have no idea what it is and how it works. I will not introduce LDAP in detail here, just a brief introduction to the protocol.
LDAP is a protocol used to publish directory information to many different resources. Usually it is used as a centralized address book, but it can be more powerful depending on the needs of the organizer.
The most basic form of LDAP is a standard way to connect to a database. The database is optimized for read queries. So it can get the results of the query quickly, but in other ways, such as updates, it's much slower. It is particularly noteworthy that LDAP is typically used as a hierarchal database rather than as a relational database. Therefore, its structure is better represented by a tree than by a table. Because of this, you cannot use SQL statements.
In short, LDAP is a quick way to get centralized, static data about people or resources.
Requirements
Phpv.4 (Previous versions can be, but not tested), compiled to support LADP, that is, the use of compile-time with--WITH-LDAP public LDAP directory. In the example, two were provided.
Example overview
1. Set up information for the public LDAP server
2. Create an LDAP query
3. Connecting to an LDAP server
4. If the connection succeeds, process the query
5. Formatted output
6. Close the connection
7. Design the HTML form of the search interface
8. Display Results
Setting up information for public LDAP servers
The first thing we need to do is define all the LDAP servers we want to search for.
"Ldap_name" = Name of the new LDAP project
"Ldap_server" = IP address or host name of the new LDAP project
"LDAP_ROOT_DN" = Distinguished name of the root of the new LDAP project
? 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] = "";
Set it to 0 if no server is selected
if (! $SERVER _id)
$SERVER _id=0;
? >
Establishing an LDAP query
As mentioned earlier, LDAP queries are not the same as SQL queries. Therefore, the statement is subject to a certain limit, the following is a basic example.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.