Home arrow PHP arrow Page 3 - Using PHP With LDAP (part 1)

The Bare Necessities - PHP

Among its many other capabilities, PHP also comes with afull-featured API to connect to, and communicate with, LDAP directoryservers. This article explores how PHP and LDAP can be used together,beginning with a crash course in LDAP basics and proceeding to a series ofsimple examples that demonstrate how PHP can be used to search an LDAPdirectory and format the results for the Web.

  1. Using PHP With LDAP (part 1)
  2. Looking For Answers
  3. The Bare Necessities
  4. Code Poet
  5. Anatomy 101
  6. What's In A Name?
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 34
April 04, 2003

print this article


In order to get started with PHP and LDAP, there are a couple of things you need.

First, you need a LDAP server, which you can use as the foundation for your PHP scripts. While there are many commercial LDAP servers, the one used in this article is the OpenLDAP server, which is robust, scalable and - best of all - free. You can download a copy from http://www.openldap.org(this tutorial uses OpenLDAP 2.1.16).

Once you've got your LDAP server up and running, it's time to populate it with some entries. Here are the sample entries that I will be using throughout this tutorial.

dn: dc=my-domain, dc=com objectClass: dcObject objectClass: organization o: MyOrganization dc: my-domain.com dn: mail=root@my-domain.com, dc=my-domain, dc=com objectClass: inetOrgPerson cn: Keith sn: Richards mail: root@my-domain.com dn: mail=joe@my-domain.com, dc=my-domain, dc=com objectClass: inetOrgPerson cn: Joe sn: Somebody mail: joe@my-domain.com dn: mail=sarah@my-domain.com, dc=my-domain, dc=com objectClass: inetOrgPerson cn: Sarah sn: Nobody mail: sarah@my-domain.com telephoneNumber: 23 67 128 5639
Refer to the OpenLDAP reference manual, or the usage guide that shipped with your LDAP server, for the exact commands needed to import this data into your LDAP directory. Note that the server must be set up to allow read access without a password, and its base DN should be "dc=my-domain, dc=com", as in the sample data above.

Once the LDAP server has been set up, the next step is to configure PHP to communicate with this server. PHP 4.3 supports this via its LDAP extension, which is not activated by default - you may need to recompile your PHP binary with the "--with-ldap" parameter to activate LDAP support (Windows users get a pre-built binary with their distribution).

Once you've got PHP configured with LDAP support, check to see that all is well via a quick call to phpinfo() - you should see something like this:

>>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: