2013-07-19 89 views
14

我有一個ldap連接問題。LDAP操作錯誤

$hostname="ldap://sub.domain.com"; 
$ds=ldap_connect($hostname, 389); 
ldap_set_option ($ds, LDAP_OPT_REFERRALS, 0) or die('Unable to set LDAP opt referrals'); 
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version'); 

if ($ds) 
{ 
$dn = "OU=Users,OU=ro,DC=sub,DC=domain,DC=com"; 

if (!($ldapc=ldap_bind($ds))) { 
    echo "<p>Error:" . ldap_error($ds) . "</p>"; 
    echo "<p>Error number:" . ldap_errno($ds) . "</p>"; 
    echo "<p>Error:" . ldap_err2str(ldap_errno($ds)) . "</p>"; 
    die; 
} 

$attributes = array("sn"); 
$filter = "(sn=*)"; 
$result = ldap_search($ds, $dn, $filter, $attributes); 

echo $result; 
$info = ldap_get_entries($ds, $result); 
for ($i=0; $i < $info["count"]; $i++) { 
    echo $info[$i]["ou"][0]; 
} 
} else { 
    echo "<h4>Unable to connect to LDAP server</h4>"; 
} 

ldap_unbind($ds); 

的LDAP的匿名連接的作品,因爲我的AD瀏覽器中測試它,一切都很好。 在此代碼它停在

ldap_search($ds, $dn, $filter, $attributes); 

我收到警告:

警告:ldap_search()搜索:在操作錯誤.. \的index.php上線38

我真的不知道可能是這個錯誤的原因,我感謝你的幫助。

+1

你沒有迷路可變範圍:

我通過設置這個選項與Active Directory的工作解決了嗎? $ dn(用於搜索的基本dn)定義在ldap_search調用的下一級。在調用搜索之前嘗試回顯(var_dump)ldap搜索參數,以確保一切正常,或者包含isset($ dn)檢查。或者無條件地定義$ dn。 –

+0

參數沒問題,我在搜索電話之前檢查了他們,這沒關係。我認爲可能的一個問題是,我在intranet上,我沒有管理員權限,所以我不能用C寫。我複製了xampp檔案,我沒有在這臺機器上安裝xampp。首先,即使我從php.ini啓用了ldap擴展,它也不起作用,因爲我在C/windows/system中沒有某個文件。當我複製他們一切正常,我想。那麼,安裝可能是一個問題? –

+0

使用shell工具檢查或Apache DirectoryStudio(LDAP客戶端GUI)如何?你不需要是本地管理員來安裝/使用它,在Linux或Windows工作流程中,無論如何。嘗試使用除PHP以外的任何其他工具連接和查詢ldap服務器。 –

回答

16

得到它沒有答案的列表:


我發現這個問題,是綁定的問題。服務器接受匿名綁定,但不接受搜索。並與用戶和通行證工作,但我犯了一個錯誤。對於用戶,我認爲只是de窗戶的用戶名不是AD的全部位置,現在它可以工作。

+0

對我來說確切同樣的問題。匿名綁定沒有錯誤,但是當搜索時出現「Warning:ldap_search():Search:Operations error in ..」。在綁定上提供有效的AD用戶/傳遞修復了搜索。 $ ldapbind = @ldap_bind($ ldapconn,$ ldaprdn,$ password); – RobDigital

7

有這個問題,但我正確地綁定了被允許搜索的用戶。

ldap_set_option($connection, LDAP_OPT_REFERRALS, 0); 
+0

這似乎也幫助我:'ldap_set_option($ connection,LDAP_OPT_PROTOCOL_VERSION,3);' – bgStack15