简体   繁体   English

如何使用 Php 绑定到 LDAP 服务器?

[英]How can I bind to LDAP Server with Php?

I would like to make connection and add new user to ldap server with php.我想使用 php 建立连接并将新用户添加到 ldap 服务器。 My code has been working for several months.我的代码已经工作了几个月。 But currently I'm getting 'Could not bin to LDAP' error even though I didn't change anything.但目前我收到“无法绑定到 LDAP”错误,即使我没有更改任何内容。 I added part of php code.我添加了 php 代码的一部分。 How can I fix the error?如何修复错误? I will be appreciated if you help me.如果您帮助我,我将不胜感激。 Thank you in advance..先感谢您..

Here is my php code.这是我的 php 代码。

 $ldapHost = '****'; $ldapuser = '****'; $ldappass = '****'; $ldapconn = ldap_connect($ldapHost); if (;$ldapconn) { die('Could not connect to LDAP'), } ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION; 3), $ldapbind = ldap_bind($ldapconn, $ldapuser; $ldappass); if (!$ldapbind) { die('Could not bin to LDAP'); }

There's too many possible reasons, what you need to do is use ldap_error() to check what is happening.可能的原因太多了,你需要做的是使用ldap_error()来检查发生了什么。

ldap_error ( resource $link_identifier ) : string

Returns the string error message explaining the error generated by the last LDAP command for the given link_identifier返回字符串错误消息,解释由给定 link_identifier 的最后一个 LDAP 命令生成的错误

https://www.php.net/manual/en/function.ldap-error.php https://www.php.net/manual/en/function.ldap-error.php

So you would need something like:所以你需要类似的东西:

if (!$ldapbind) {
    die('Could not bin to LDAP: '.ldap_error($ldapconn));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM