$adServer = 'domain.something.com'; //replace with your AD server ip/hostname
$ldaprdn = $username . '@' . $adServer; //other format $ldaprdn = "DOMAIN\\" . $username;
//Connecting to server
$ldapconn = ldap_connect($adServer)
or die(); #connection resource -> always 1
ldap_set_option($ldapconn, LDAP_OPT_NETWORK_TIMEOUT, 5);
ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 30);
//Connect to Server
if ($ldapconn)
{
if ($ldapbind = @ldap_bind($ldapconn, $ldaprdn, $password))
{
//Succesfull Authentication
return TRUE;
} else
{
//Unsuccesfull Authentication
return FALSE;
}
} else
{
// Could not connect to AD server.
return FALSE;
}