<?php
  $login_err
['ad'] = null;
  
// Connect to the directory server.
  
if (!$ad ldap_connect('ldap://msactivedirectoryserver'))
    
$login_err['ad'] = 'Authentication Not Performed: Connection to Auth Server failed!';
  if (!
ldap_set_option($adLDAP_OPT_PROTOCOL_VERSION3))
    
$login_err['ad'] = 'Authentication Not Performed: Failed to set LDAP protocol version to 3';
  if (!
ldap_set_option($adLDAP_OPT_REFERRALS0))
    
$login_err['ad'] = 'Authentication Not Performed: Failed to set referrals option!';
  if (
ldap_bind($ad) && ldap_errno($ad) !== 0)
    
$login_err['ad'] = 'Authentication Not Performed: Connection to Auth Server failed!';
  
$user 'login_name_here' '@YourDomain';
  
$pass 'password_here';
  if (!
$bd ldap_bind($ad ,$user$pass))
    
$login_err['ad'] = 'Authentication Failed: Login/Password Incorrect';
  
// Carry out directory server-specific tasks.
  
  //check if login failed;
  
if ($login_err['ad'] != null)
    return 
false;

  
// Close the connection
  
ldap_unbind($ad);
?>