0

I've just started working on LDAP and trying make an connection between PHP & LDAP.

I've created small script to get all attributes information by referring this script.

$ldap_server = "My_Server_Name";
$ldap_user = "uid=platypus,ou=users,dc=crowd";
$ldap_pass = "My_Password";

$ad = ldap_connect($ldap_server);
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
$bound = ldap_bind($ad, $ldap_user, $ldap_pass);

$result = ldap_read($ad, $ldap_user, "objectClass=*");
$attributes = ldap_get_attributes($ad, $result);

echo "<pre>";
print_r($attributes);

Connection is successfully made, its binding properly as well and ldap_read also giving me #resourse id but ldap_get_attributes giving me following error:

PHP Warning – yii\base\ErrorException ldap_get_attributes(): supplied resource is not a valid ldap result entry resource

Any help would be appreciated.

Thanks

vishuB
  • 4,173
  • 5
  • 31
  • 49
J.K.A.
  • 7,272
  • 25
  • 94
  • 163

2 Answers2

1

ldap_get_attributes() expects the input parameter to be a reference to a single entry not to the complete resultset as stated on the ldap_get_attributes-documentation.

Have a look at ldap_get_first() or ldap_get_next() to get such a single entry reference.

Thanks to tejesh s for pointing in the right direction. I originally wanted to improve his answer but it was too much change :/

heiglandreas
  • 3,803
  • 1
  • 17
  • 23
0

ldap_get_attributes() expect input parameter to be an single entry not an array. http://php.net/manual/en/function.ldap-get-attributes.php.

I hope this will help you.

tejesh s
  • 121
  • 9