title: LDAP and PHP connection failure
body: <p>I am trying to connect to a secure LDAP server (using LDAPs) via PHP, but I am having problems with it. I get the following error</p>
  
  <blockquote>
    <p>Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in /var/www/test.php on line 16</p>
  </blockquote>
  
  <p>I works when I try to connect without LDAPs, but it is required that I use LDAPs because I am going to be dealing with sensitive information.</p>
  
  <p>I am using the following code</p>
  
  <pre><code>&lt;?php
  // basic sequence with LDAP is connect, bind, search, interpret search
  // result, close connection
  
  echo "&lt;h3&gt;LDAP query test&lt;/h3&gt;";
  echo "Connecting ...";
  $ds=ldap_connect("ldaps://server");  // must be a valid LDAP server!
  
  
  
  
  print $ds;
  
  if ($ds) { 
      echo "&lt;br&gt;&lt;br&gt;Binding ..."; 
      $r=ldap_bind($ds);     // this is an "anonymous" bind, typically
                             // read-only access
      echo "Bind result is " . $r . "&lt;br /&gt;";
  
      echo "Searching for (sn=S*) ...";
      // Search surname entry
      $sr=ldap_search($ds, "ou=people,o=server.ca,o=server", "uid=username*");  
      echo "Search result is " . $sr . "&lt;br /&gt;";
  
      echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "&lt;br /&gt;";
  
      echo "Getting entries ...&lt;p&gt;";
      $info = ldap_get_entries($ds, $sr);
      echo "Data for " . $info["count"] . " items returned:&lt;p&gt;";
  
  print_r($info);
  //    for ($i=0; $i&lt;$info["count"]; $i++) {
  //        echo "dn is: " . $info[$i]["dn"] . "&lt;br /&gt;";
  //        echo "first cn entry is: " . $info[$i]["cn"][0] . "&lt;br /&gt;";
  //        echo "first email entry is: " . $info[$i]["mail"][0] . "&lt;br /&gt;&lt;hr /&gt;";
  //    }
  
      echo "Closing connection";
      ldap_close($ds);
  
  } else {
      echo "&lt;h4&gt;Unable to connect to LDAP server&lt;/h4&gt;";
  }
  ?&gt;
  </code></pre>