LDAPS无法与PHP连接

时间:2012-01-17 06:15:52

标签: php active-directory ldap

我在使用Windows连接到安全的LDAP服务器时遇到了问题,我在网上到处都看到同样的事情,到目前为止还没有解决方案。

我尝试过使用IIS和WAMPSERVER。我已经将libeay32.dll和ssleay32.dll放在我的SYSTEM32目录中并启用了LDAP扩展。

这是我的代码:

putenv('LDAPTLS_REQCERT=never');
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$resource = ldap_connect("ldaps://{redacted}/", 636) or die ("Could not connect.");
ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3)
$bound = ldap_bind($resource, "{redacted}\ldap", "****");

echo ldap_error($resource);

我从ldap_error获取Can't contact LDAP server并且PHP警告Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in C:\wamp\www\ldapTest.php

我尝试连接的服务器正在运行Active Directory,我已确认可以使用其他LDAP工具进行连接。我知道这个服务器的证书有问题 - 我使用的LDAP工具是The server you are trying to connect to is using a certificate which could not be verified! - Issuer certificate not found

我怀疑是错误的证书导致绑定问题,这就是为什么我尝试过LDAPTLS_REQCERT = never。

2 个答案:

答案 0 :(得分:1)

我不记得我在哪里发现了这篇文章;但是我发现默认情况下,即使你指定TLS_REQCERT也不会被忽略。

我发现/然后忘记并再次发现你需要做以下事情(对于Windows机器)

  1. 在根目录中的驱动器c上创建以下目录结构 c:\ OpenLDAP \ sysconf(创建两个文件夹)
  2. 在sysconf文件夹中创建一个名为“ldap.conf”的文本文件
  3. 在您创建的文本文件中,将以下内容放在第一行,然后保存 “TLS_REQCERT never”(没有引号)
  4. 重新启动Apache,现在应该可以正常工作了。
  5. 试一试。祝你好运!

答案 1 :(得分:0)

您可以尝试更改以下行:

$resource = ldap_connect("ldaps://{redacted}/", 636)

直接在URI中使用您的端口号

$resource = ldap_connect("ldaps://{redacted}:636")

当其他人不这样做时,这已经知道了。

相关问题