PHP 警告:ldap_bind():无法绑定到服务器:无法联系 LDAP 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5309372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:57:16  来源:igfitidea点击:

PHP Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server

phpldap

提问by Pascal Bayer

I've following problem with my php script:

我的 php 脚本有以下问题:

PHP Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in ....

PHP 警告:ldap_bind():无法绑定到服务器:无法在...中联系 LDAP 服务器。

ldap_connect()says "Success" but ldap_bind()fails, how to fix that issue?

ldap_connect()说“成功”但ldap_bind()失败了,如何解决这个问题?

采纳答案by geoffc

Connect opens the session. Bind is what actually authenticates you. Thus you connected but did not login with valid credentials.

Connect 打开会话。绑定实际上是对您进行身份验证的内容。因此,您已连接但未使用有效凭据登录。

回答by WhoIsRich

Had this error on RHEL7 ( CentOS7 ) due to SELinux restricting ports HTTPD can use.

由于 SELinux 限制 HTTPD 可以使用的端口,在 RHEL7 ( CentOS7 ) 上出现此错误。

LDAP ports 389 and 636 are not on the default allow list, you can unblock with:

LDAP 端口 389 和 636 不在默认允许列表中,您可以通过以下方式取消阻止:

setsebool -P httpd_can_network_connect 1

You can test for the restriction by trying a socket to the LDAP server:

您可以通过尝试连接到 LDAP 服务器的套接字来测试限制:

fsockopen('LDAP-Server-IP', 389);

It will give 'Permission Denied' showing it's blocked and not a credentials issue.

它将给出“权限被拒绝”,显示它已被阻止,而不是凭据问题。

Also check your SELinux audit log file for other things being blocked.

还要检查您的 SELinux 审核日志文件是否有其他被阻止的内容。

回答by Kevin FERRANDON

Sometime the problem will depend of your environment(Linux, Windows...) Try to bind with one of this options:

有时问题将取决于您的环境(Linux、Windows ...)尝试使用以下选项之一进行绑定:

$connect = ldap_connect("ldap://".$ldap_server);
$auth_user = 'CN=XXX,OU=XXX,DC=XXX,DC=com';
$bind = ldap_bind($connect, $auth_user , $auth_pass);

or

或者

$bind = ldap_bind($connect, 'YourDomaine\'.$auth_user , $auth_pass);

回答by user806168

the ldap_bind() function asks for a three parameters:

ldap_bind() 函数需要三个参数:

  1. a resource id
  2. a rdn
  3. a password associated with the rdn the rdn and password are optional
  1. 资源标识
  2. 编号
  3. 与 rdn 关联的密码 rdn 和密码是可选的

if you bind using only the resource id :-

如果您仅使用资源 ID 进行绑定:-

// $ldap=ladap_connect(*hostname*,*port*);  
// ldap_connect() returns a resource id
ldap_bind() returns a boolean value(true or false)  
ldap_bind($ladp); //annonymous bind    
$lb=ldap_bind($ldap,"uid=xxx,ou=something,o=hostname.com","password"); //used to authenticate  

this should work if not then you are using invalid credentials.

如果没有,这应该可以工作,那么您使用的是无效凭据。