Overview

The below PHP script is an example of how to connect to Active Directory via LDAP and retrieve a list of users details.

Requirements

To use this script your PHP web server will need the LDAP module installed,  you can verify the installation by creating a phpinfo file.

phpinfo.php

When browsing to this web page you should see an ldap section;

PHPInfo LDAP Section

If you don’t see an ldap section in your phpinfo results you will need to install the php ldap package, for example on Ubuntu / Debian;

Install php5-ldap:
sudo apt-get install php5-ldap
Reboot apache
/etc/init.d/apache2 restart

Variables  to change

You will need to change the variables;

The Script