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


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


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

Author: Phil Eddies

I am an IT Operations Manager, managing all aspects of the IT infrastructure and service for a mid sized UK based company. I have been working full time in IT since 2001 in 1st to 3rd line and System Administration roles. MCSA, MCSE, CCNA, Citrix CCA