How to Connect PHP to LDAP
The other day I needed to connect PHP to my organization's LDAP/Active Directory server. I hadn't done this before and found it pretty difficult/annoying.
Hopefully, this will help someone else in the future or even just the future version of me if I have to do this again. I've heavily commented the code below for clairity. We are just outputing a form that asks for the LDAP credentials. If we do not have any relevant $_POST
values submitted to our webpage/server we output the form. Otherwise, we will attempt to login to the LDAP server with the credentials provided and retrive some of the user's information.
Now that the user has passed authentication, you could check to see if the user is part of a certain group or has certain value(s) associated with their account.