安装信息:
我有两个 Windows 服务器。一个 (Windows Server 2008 R2) 是带有 Active Directory (AD) 的域 Controller (DC)。它的名称是 s1.xyz.com。第二台(Windows Server 2003 R2)服务器正在运行 IIS,第二台服务器上安装了 PHP.SSL 证书。
我已经在 DC 服务器上安装了 Active Directory 证书服务作为证书颁发机构 (CA) 并使用以下链接启用 LDAP over SSL (LDAPS):
http://www.christowles.com/2010/11/enable-ldap-over-ssl-ldaps-on-windows.html
问题是什么:
实际上,我想为 AD 用户设置密码,所以我的要求是安全连接(LDAPS)。
我可以在不安全的端口 (389) 上成功连接到 DC 并访问 AD 数据,但是
我无法使用 PHP ldap_bind() 函数将用户绑定(bind)到安全连接(在端口 636 上)。
当我运行脚本时,它给出“ldap_bind() [function.ldap-bind]:无法绑定(bind)到服务器:无法联系 LDAP 服务器”错误。
代码:
$ip="xxx.xxx.xxx.xx";
$ldaps_url="ldaps://s1.xyz.com:636/";
$ldap_url="s1.xyz.com";
$ldapUsername ="Administrator@xyz.com";
$ldapPassword="x1y1z1";
$ds=ldap_connect($ldaps_url);
//$ds=ldap_connect($ip,636);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ds, LDAP_OPT_REFERRALS,0);
$bth=ldap_bind($ds, $ldapUsername, $ldapPassword);
ldap_unbind($ds);
$ds="";
最佳答案
如果您正在使用 SSL(例如 ldaps)并且 ldap_bind 抛出“无法绑定(bind)到服务器:”错误,请检查 ldap_connect 中使用的主机名是否与 SSL 中的“CN”匹配LDAP 服务器上的证书。例如:
<?
ldap_connect('ldaps://ldap01');
// 'ldap01' should match the CN in your LDAP server's SSL cert, otherwise the subsequent ldap_bind() will throw a bind error
?>
您可以使用 Microsoft MMC 查看您的证书。
关于php - 无法通过与 php 的安全连接绑定(bind)到 LDAP 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8835913/