I try to connect to openLDAP with PHP, but I get the following error:
Warning: LDAP: Unable to bind to server: Protocol error in /usr/local/httpd/htdocs/testdomain/connect_anonym.php on line 12
anonymes LDAP bind fehlgeschlagen...
Can anyone help me?
Should I change something in the slapd.conf?
When I open the phpinfo, LDAP is present:
LDAP Support enabled
RCS Version $Id: ldap.c,v 1.82.4.2 2001/05/30 21:18:17 rasmus Exp $
Total Links 0/unlimited
API Version 2004
Thanx bye...
My System: Apache/1.3.19 (Unix) (SuSE/Linux) PHP/4.0.6
and I use openLDAP 2.1.22
Here my connect file:
<?php
//verwenden von anonymen ldap bind
// verbinden zum ldap server
$ldapconn = ldap_connect("localhost", 389)
or die("Could not connect to LDAP server.");
Your code is fine, I tested it and it worked. The only thing that comes to mind is that it can't find the server, ie localhost.
When I only try the connect there are no errors!
This is because the connect function doesn't really connect to the server, it just creates a resource. There is no connection attempt until you do ldap_bind() then it checks the server.
Another thing it could be that anonymous bind isn't allowed.
So try your IP first if that still doesn't work, try something like this from your terminal:
ldapsearch -x -s base -b "dc=udb,dc=fam" "objectClass=*"
This should display something, if it does it means anonymous access is allowed and your server is running, if it errors or can't connect or something, then something else is wrong.
Hey,
with the command:
ldapsearch -x -s base -b "dc=udb,dc=fam" "objectClass=*"
Now I tried this:
(and set in the slapd.conf: allow bind_v2)
The bind is successful, but in the LDAP Log the error:
ber_get_next on fd 7 failed errno=11 (Resource temporarily unavailable)
do_unbind
IŽam disperated!
Joe
<?php
// get a connection
$ldap=ldap_connect("localhost", 389);
// check to see if we got one, if we did, proceed
if($ldap)
{
if(!$passWord)
{
// generate a bogus password to pass if the user doesn't give us one
// this gets around systems that are anonymous search enabled
$passWord = crypt(microtime());
}
}
echo "connect: ".$ldap."<p>";
$ldapbind = ldap_bind($ldap);
echo "bind: " .$ldapbind."<p>";
//$sr=ldap_search($ldap,"dc=my-domain, dc=com", "(cn=Keith)" );
// echo "Search result is ".$sr."<p>";
// using ldap bind
$ldaprdn = "cn=Manager,dc=my-domain,dc=com"; // ldap rdn or dn
$ldappass = "secret"; // associated password
// connect to ldap server
$ldapconn = ldap_connect("localhost", 389)
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
$sr1=ldap_search($ldap,"dc=my-domain, dc=com", "(mail=root*)" );
echo "Search result is ".$sr1."<p>";
?>
Like I said your code looks fine and your server is running anonymous access is allowed but it seems PHP can't bind to it, did you try putting the IP in instead of localhost?
Resource temporarily unavailable that would normally mean the server isn't running (but it is if ldap_search worked) or something can't access it properly.
I had a similar problem. In the end it turned out that I used the wrong LDAP version (2) when instead I had to do an LDAP Bind with v3 of the protocol