title: Couldn't bind LDAP using PHP
body: <p>I try to bind LDAP using PHP and I getting this error</p>
  
  <pre><code>    Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server on line 21
  </code></pre>
  
  <p>and the script on line 21 is this..</p>
  
  <pre><code>    $bind_status = ldap_bind($conn_status, $app_user, $app_pass);
  </code></pre>
  
  <p>Here's the script to connect in LDAP:</p>
  
  <pre><code>   $conn_status = ldap_connect('ldaps://ldap.domain.com/', 389);
      if ($conn_status === FALSE) {
          die("Couldn't connect to LDAP service");
      } else {
          echo "Successful! &lt;br/&gt;";
      }
  </code></pre>
  
  <p>Here's the script of Bind to LDAP:    </p>
  
  <pre><code>    $app_user = 'cn=user, dc=domain, dc=com';
      $app_pass = 'password';
  
      $username = 'user'; //same as cn
      $password = 'password'; //same as $app_pass
  
      $bind_status = ldap_bind($conn_status, $app_user, $app_pass);
      if ($bind_status === FALSE) {
          die("Couldn't bind to LDAP as application user");
      } else {
          echo "Bind to LDAP successfully &lt;br/&gt;";
      }
  </code></pre>
  
  <p>My updated LDAP bind script</p>
  
  <pre><code>    $bind_status = ldap_bind($conn_status, $username, $password);
      if ($bind_status === FALSE) {
          //die("Couldn't bind to LDAP &lt;br/&gt;");
          echo "LDAP-Errno: " . ldap_errno($ds) . "&lt;br /&gt;";
      } else {
          echo "Bind to LDAP successfully &lt;br/&gt;";
      }
  </code></pre>
  
  <p>And now I got this error:</p>
  
  <pre><code>    Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Operations error on line 21
  </code></pre>
  
  <p>Line 21 is this:</p>
  
  <pre><code>    $bind_status = ldap_bind($conn_status, $username, $password);
  </code></pre>
  
  <p>When I use</p>
  
  <pre><code>    var_dump (@ldap_bind($conn_status, "cn=Username, ou=domain, ou=com"));
  </code></pre>
  
  <p>The result is </p>
  
  <pre><code>    bool(false)
  </code></pre>
  
  <p>Pls help me to fix this. Thank you</p>