How to Authenticate With ActiveDirectory LDAP Using PHP

Use PHP’s LDAP support.

After installing it for your particular environment (I had PHP in a Linux environment), you can use the following function to verify AD access. In my case, I just wanted to ensure the user’s login was valid in AD and controlled ACL via the application database.

define('LDAP_SERVER', "ldap.server.com");
  
function verifyADLogin($username, $password) {
  $username = "$username@server.com";
  $ldap = ldap_connect(LDAP_SERVER);
  if($password != "") {
    if(ldap_bind($ldap, $username, $password)) {
      ldap_unbind($ldap);
      return true;
    }
  }
  return false;
}