I want to do an ldap serach using the basic functions of php. I have a problem with the resource returned by ldap connection (function ldap_connect()). It seems to be working fine but I’m getting this warning when it comes to ldap bind :
Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in ..
And then ldap_error() returns the following warning :
Warning: ldap_error() expects parameter 1 to be resource, boolean given in..
I made a var_dump to see the value returned by ldap_connect. Here is the complete code:
<? php
$host = "ldaps://valid.host.name.fr";
$port = 636;
$username = 'uid=HEDE45,ou=Applis,dc=ldapannuaire';
$password = 'mdp1234';
$baseDn = 'dc=ldapannuaire';
$person = 'JACKSON';
$filter="(sn=$person*)";
$connectStr = $host.":".$port;
echo "Connecting ...\n";
$ds = ldap_connect($connectStr);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0) or die('Unable to set LDAP referrals'); // We need this for doing an LDAP search.
if ($ds) {
echo "Binding ...\n";
var_dump($ds);
$bind = ldap_bind($ds, $username, $password);
ldap_error($bind);
if ($bind) {
echo "LDAP bind successful...\n";
$search = ldap_search($ds, $baseDn, $filter) or exit("Unable to search LDAP server, response was: " . ldap_error($search));
// Search users
$info = ldap_get_entries($ds, $search);
echo $info["count"]." entries returned\n";
// close connection
ldap_unbind($bind);
} else {
echo "LDAP bind failed...\n";
}
}
ldap_close($ds);
I execute my code in an SSH terminal using the command line. I get the following result:
[webadmin@myserverfaraway~]$ /software/apache/apa_2.2.24/php-5.3.23/bin/php -c /myproject/apache_2.2.24/php_5.3.23/conf/php.ini /myproject/apache_2.2.24/htdocs/chrons/searchPeople.php
Connecting ...
Binding ...
resource(8) of type (ldap link)
Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in /myproject/apache_2.2.24/htdocs/chrons/searchPeople.php on line 21
Warning: ldap_error() expects parameter 1 to be resource, boolean given in /myproject/apache_2.2.24/htdocs/chrons/searchPeople.php on line 22
LDAP bind failed...
[webadmin@myserverfaraway ~]$
I don’t understand why after the bind, I have a boolean instead of having the ldap resource link (resource(8) of type (ldap link)). Can someone help me find the problem?
Thanks..
$ds = ldap_connect('valid.host.name.fr', 636);- EricLavaultldap_search? - EricLavault