我在尝试使用 URL('ldap://hostname/')从 PHP5 的 Ubuntu 服务器连接到 LDAP 服务器时遇到问题。
当我不使用 URL 格式 ($server = 'hostname'
) 时,代码工作正常。
代码:
$server = 'ldap://hostname/';
$ldapconn = ldap_connect($server, 3268) or die("Could not connect to LDAP server.");
if ($ldapconn) {
$ldapbind = @ldap_bind($ldapconn, 'username', 'password');
$error_ldap_code = ldap_errno($ldapconn) ;
if($error_ldap_code==0) {
echo 'Connected!!!';
}
}
编辑:
我需要ldaps
,但我看到使用ldap
我遇到了同样的问题。虽然通过在 URL 中添加端口解决了与 ldap 相关的问题,但我仍然遇到 ldaps 问题。无论如何,在仅使用主机名(无 URL 格式)连接后,我设法通过使用 ldap_start_tls ( resource $link )
绕过了它。
最佳答案
尝试在 URL 中指定端口 - 它不是标准端口 389。所以 'ldap://hostname:3268'?
关于使用 URL 的 PHP LDAP 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16646659/