title: How to perform a LDAP SASL bind to Active Directory using GSS-API mech in PHP from Windows?
body: <p>I have an Active Directory server and a Windows WAMP server hosting PHP web applications that need to be able to authenticate to Active Directory using Kerberos.</p>
  
  <p>I was able to easily connect and bind to the Active Directory host using some sample PHP code, but I'm not sure how to do so with Kerberos. I have see many forums and blogs detailing how to do this on *NIX machines, but that doesn't help me with my situation.</p>
  
  <p>I did use Wireshark and <a href="http://fiddler2.com/home" rel="nofollow">Fiddler</a> to confirm that there is no Kerberos or NTLM negotiating happening.</p>
  
  <p>Sample code I used to connect and bind to LDAP:</p>
  
  <pre><code>&lt;?php   
     $ldaphost = "example.domain.com";
     $ldapport = 389;
     $ldapuser = "user";
     $ldappass = "password";
  
      $ldapconn = ldap_connect( $ldaphost, $ldapport )
      or die( "Unable to connect to the LDAP server {$ldaphost}" );
  
      if ($ldapconn)
      {
          $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);
  
          if ($ldapbind)
          {
              echo "LDAP connection successful";
          }
          else
          {
              echo "LDAP connction failed";
          }
      }
  ?&gt;
  </code></pre>
  
  <p>Any help will be greatly appreciated, thanks!</p>
  
  <p><strong>Update:</strong> I've been wrestling with this all day and I think I need to use ldap_sasl_bind(), possibly using GSSAPI as the mechanism... No matter what parameters I put in to ldap_sasl_bind(), I get the following error: 'Unable to bind to server: Unknown authentication method'</p>
  
  <p>I'm not sure how to implement GSSAPI, but some examples I've seen show using ldap_start_tls(), but I keep getting a 'Unable to start TLS: Server is unavailable' error.</p>
  
  <p>I don't know if anyone knows anything about ldap_sasl_bind() (which is undocumented by PHP) or ldap_start_tls, but if this is the way I should be going, please point me in the right direction.</p>