提供的资源不是有效的ldap结果条目资源:ldap_get_attributes()

时间:2015-08-31 10:57:12

标签: php ldap yii2 openldap ldap-query

我刚刚开始处理LDAP并尝试在PHP和{}之间建立联系。 LDAP

我创建了一个小脚本,通过引用this获取所有属性信息 脚本。

$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);

连接成功,绑定也正常,ldap_read也给了我#resourse idldap_get_attributes给了我以下错误:

  

PHP警告 - yii \ base \ ErrorException       ldap_get_attributes():提供的资源不是有效的ldap结果条目资源

任何帮助都将不胜感激。

由于

2 个答案:

答案 0 :(得分: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 :/

答案 1 :(得分:0)

ldap_get_attributes()期望输入参数是单个条目而不是数组。 http://php.net/manual/en/function.ldap-get-attributes.php

我希望这会对你有所帮助。