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', "");
function verifyADLogin($username, $password) {
  $username = "$";
  $ldap = ldap_connect(LDAP_SERVER);
  if($password != "") {
    if(ldap_bind($ldap, $username, $password)) {
      return true;
  return false;