Connection to LDAP in PHP isn't that easy task by itself. Things get even more complicated, if you're working in XAMPP environment under Windows. It hope this article will help you in getting un-stuck, if you're stuck on the similar things, as I did.
Notice: solution provided in this article may not work for you! It worked on my office computer and failed completely on my home computer, though both are quite similar (same version of Windows and XAMPP etc.).
Since, we're talking about very stupid system (Windows) and about even more stupid situation (claiming, that file is not found, though it exists in folder listed in
PATH variable), I have no bloody idea, why it doesn't work (or why it does work on certain computers) and how to solve this problem.
To use LDAP support in PHP served under Windows you need to have three libraries:
You have to put them into
system32 folder, if you're serving your PHP through XAMPP.
So, information provided in PHP documentation about installation of LDAP support in
Note to Win32 Users is wrong and comment provided by user named Frank is correct. You need to have
libsasl.dll library not only for very old PHP 4.3 or older. Even newest versions of PHP 5.3 and above require this lib.
What is even more strange, I had this library (along with required
libeay32.dll) in my PHP's directory and my PHP's directory was listed in Windows'
PATH variable. And even so, I'm facing the problem of Apache failing to start. The only workaround, I found, was to copy
system32 system directory. Solution, that PHP documentation here discourages.
So, to summarize, section
Note to Win32 users is twice wrong (at least in form from writing this article; I posted note to update it). You do have to have
libsasl.dll library and you must place it in system folder.
You have to edit your
php.ini file and uncomment
extension=php_ldap.dll line. Then you have to restart your Apache / XAMPP / server.
If you don't have above mentioned libraries, next run of server will fail with information, which directory is missing. Newest XAMPP brings these libraries in
XAMPPphp folder, so you only have to copy them to
system32 folder, because for some strange reason, libraries in
XAMPPphp are not loaded, though all of them are in
PATH system environment variable.
Copy all of these libraries (or just
libsasl.dll, as many other programs are using
libeay32.dll libraries and one of them could already put these two libs) to your
Next Apache restart should go without any problems and your code should be able to login to LDAP server.
For examples of authenticating user in LDAP see my Logging user to LDAP directory under Yii text.