This video, we’ll show you how to connect to Active Directory from PHP using LDAP Before we begin, you’ll need to enable LDAP extension on your PHP server first Locate the php.ini file on your server Make sure that the line “extension=php_ldap.dll” is uncommented by removing semi-colon Then save and close the php.ini Next, make sure that you got the 2 following DLL files First is libeay32.dll And another is ssleay32.dll If you’re using XAMPP then they should be already there. If not, you can download them from the internet Restart the server and we’re ready to go There are 2 steps to connect to Active Directory using LDAP First, we’ll use ldap_connect to connect to the active directory server In this tutorial, we’ll use an online LDAP testing server. (Special thanks to forumsys.com) After we’ve connected with the server, we’ll need to bind (authenticate) using DN (distinguished name) In PHP, we can use ldap_bind and use the connection object as a first parm The second parm is DN. In this video, we’ll bind as admin I copy the DN provided from the forumsys The last parm is password which is straight forward If the authentication is success, the ldap_bind will return a bind object but if the DN/password is invalid or there are any errors, then the function will return false One final important notes Some server were configured differently. If you got a “Protocol error” when binding, You’ll need to set a LDAP protocol version Use ldap_set_option after you have connected and the the LDAP_OPT_PROTOCOL_VERSION to 3 Now we’re ready. It’s time to test the script Success 🙂 In next video, we’ll show you how to search/get users attributes from the active directory Thanks for watching and don’t forget to subscribe too!