I am trying to bind to an LDAP server using php without success. I have a linux server running php compiled with open ldap. I am using the following code taken right from php.net:
Code: ( php )

   1.
      echo "<h3>LDAP query test</h3>";
   2.
      echo "Connecting ...";
   3.
      $ds=ldap_connect("ldap.berkeley.edu");  // must be a valid LDAP server!
   4.
      echo "connect result is ".$ds."<p>";
   5.

   6.
      if ($ds) {
   7.
          echo "Binding ...";
   8.
          $r=ldap_bind($ds);     // this is an "anonymous" bind, typically
   9.
                                 // read-only access
  10.
          echo "Bind result is ".$r."<p>";

I get a result from ldap_connect, but an error with ldap_bind. I get the following error:

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in /home/eric/public_html/academic-senate-test/authenticate/login_action.php on line 26

Here is the readout from phpinfo under the ldap section:

LDAP Support enabled
RCS Version $Id: ldap.c,v 1.161.2.3.2.11 2007/07/17 09:09:42 jani Exp $
Total Links 0/unlimited
API Version 3001
Vendor Name OpenLDAP
Vendor Version 20213

Appreciate any advice, thanks!

I can access ldap.berkeley.edu from other ldap browsers just fine. The php code is on a server separate from the ldap directory. Is there a specific way to compile php with ldap so that it knows to access a server that is not local, could this be the problem?

I have googled, found a fair number of people reporting this problem but no answers. I appreciate any advice, thanks!

Eric

    unless you have a valid LDAP authentication username/password combo AT the berkeley ldap server I doubt it's going to bind...

    Edit: Just saw the bit about anonymous binding, but I've never worked with it. Should you maybe try an LDAP server you control instead?

      Thanks Horizon - However, I have been connecting anonymously before using this same code as written. The directory has public information available to anyone and secure information that requires credentials.

        I am trying to avoid setting up a separate LDAP server, as I have not done this before and I know the current one is working. A friend mentioned that the "protocol" for the ldap server may be different than the one compiled in PHP. Is this possible? How would I check this?

        Thanks!

          Ok I found a possible solution. I connected successfully to a test ldap environment, one that is set up to not require reverse DNS lookup to permit the bind. So the ldap-bind command now works. I am now making sure I have the domain set up correctly and that the server permits reverse DNS and will try again tomorrow, and I will let folks know if this succeeds.

          It worked. Problem resolved. Always helps to discuss "out loud" : ) Eric

            3 years later

            hi eric. i need your help big time. i was searching thru google & i found this page as i m having same error problem which u were having long time back. i can understand u mite not remember it, but can u plz tell me step by step how did u remove your error of ldap_bind.
            i m using xampp (on windows 7- apache, php).

            i'l really appreciate your help.

              @: Sorry, but posting personal contact information on the forums isn't allowed.

              As for your problem, are you sure it isn't a firewall problem? If the LDAP server you're trying to connect to isn't on the same LAN as you, it's very likely that a firewall between the Internet and the LDAP server is blocking LDAP traffic.

                6 days later

                Yes i tried, i turned off the firewall, but stil no success. i really dnt have much idea how to confiure it in apache, altho i configured it in php.

                  Write a Reply...