[英]PHPs ldap_bind() failing even though ldap_connect() is successful
[英]PHP ldap_connect + ldap_bind unable to bind
我有這個PHP代碼:
$ldap = ldap_connect("aaa.bbbbb.cc")
or die("Could not connect to LDAP server.");
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$ldapbind = ldap_bind($ldap);
if ($ldapbind) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed..."; //end up here
}
我無法使其成功綁定,我嘗試了各種組合。 使用帶有“ ldap://”的URI傳遞憑據。
綁定到同一LDAP服務器時,以下C#代碼可以正常工作:
var connection = new LdapConnection("aaa.bbbbb.cc");
connection.Bind();
用於PHP的LDAP API似乎很難調試,因為如果綁定失敗,您將不會得到任何結果,因此,我不知道如何查看失敗(如果它無法訪問服務器,憑據錯誤或其他原因)。
那么,有什么想法可能導致PHP代碼失敗? 我需要做些特別的事情嗎? (已為PHP啟用LDAP擴展)
我以前在使用PHP LDAP時遇到問題。
幸運的是,我在文檔注釋中找到了這個:
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
嘗試打開連接和綁定時,這將為您提供詳細的輸出。
我通常這樣做:
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$ldap = ldap_connect("ldap://" . $domainController, $port);
$bind = @ldap_bind($ldap, $username . $accountSuffix, $password);
if (!$bind) {
// throw or something
echo ldap_error($ldap); // http://php.net/manual/en/function.ldap-error.php
}
Wikipedia很好地記錄了LDAP協議的各個部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.