How to authenticate users with Active Directory using PHP

<?php

// using ldap bind
$ldaprdn = ‘xxx@xx-xxx.com’; // ldap rdn or dn
$ldappass = ‘xxxxx’; // associated password

// connect to ldap server
$ldapconn = ldap_connect(“ldap://xx-xx.xxx-xx.com”)
or die(“Could not connect to LDAP server.”);

if ($ldapconn) {

// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

// verify binding
if ($ldapbind) {
echo “LDAP bind successful…”;
} else {
echo “LDAP bind failed…”;
}

}

?>