title: LDAP Require Cert Never with PHP
body: <p>I am trying to create a connection from php to an active directory server over ldaps. I am able to make a connection to the server if I just use ldap to connect but it isn't a secure connection. When I point php to the secure connection, it wont connect. A co-worker has given me his python code that he is using for the same connection but I am running into a problem trying to implement it in php. Here is my php code:</p>
  
  <pre><code>$connection = ldap_connect($this-&gt;ldapserver);
    $adminBind = false;
    if (ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3))
      if (ldap_set_option($connection, LDAP_OPT_REFERRALS, 0))
        if(ldap_set_option($connection, LDAP_OPT_X_TLS_REQUIRE_CERT, 0))
          $adminBind = ldap_bind($connection, $this-&gt;ldapadmindn, $this-&gt;ldapadminpw);
    if(!$adminBind)
      return false; //server down or admin account unavailable
  </code></pre>
  
  <p>And here is part of the python he sent me <code>ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)</code></p>
  
  <p>The problem comes from the line <code>ldap_set_option($connection, LDAP_OPT_X_TLS_REQUIRE_CERT, 0)</code>. I am getting a <code>Use of undefined constant LDAP_OPT_X_TLS_REQUIRE_CERT</code> error when I try to run this section. According to <a href="http://php.net/manual/en/function.ldap-set-option.php" rel="nofollow">the php page for set option</a>, this is one of the available options. Does anyone know how to get this option to work?</p>
  
  <p>One answer that I have seen is to write "TLS_REQCERT never" in the ldap.conf file. I am hoping for this one connection to ignore the certificate because the web server regularly connects to another active directory and I need that to use the certificate. </p>
  
  <p>Thanks for the help.</p>