0
我正試圖在匿名綁定的同時在LDAP中搜索用戶。首先這可能嗎?如何在使用匿名綁定的同時在LDAP中搜索用戶?
這裏是一個工作代碼。
$ldaphost = "dc.mydomain.com"; // your ldap server
$ldapport = 389; // your ldap server's port number
$ldapuser = "[email protected]";
$ldappass = "somepass";
$basedn = 'dc=mydomain,dc=com';
$searchfor = 'seconduser';
//Connecting to LDAP
$ldapconn = ldap_connect($ldaphost, $ldapport) or die("Could not connect to" . $ldaphost);
if ($ldapconn)
{
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
// binding to ldap server
$ldapbind = ldap_bind($ldapconn,$ldapuser, $ldappass);
$filter = '(&(samaccounttype=805306368)(samaccountname=' . $searchfor . '))';
$result = ldap_search($ldapconn, $basedn, $filter, array('samaccountname'));
$info = ldap_get_entries($ldapconn, $result);
echo '<pre>';
print_r($info);
}
上面的代碼唯一的事情是,我將不得不提供一個用戶進行綁定。我想以匿名方式代替。要做到這一點我改變了下面的代碼行從
$ldapbind = ldap_bind($ldapconn,$ldapuser, $ldappass);
到
$ldapbind = ldap_bind($ldapconn);
但是,這是給我下面的錯誤在ldap_search()
ldap_search(): Search: Operations error
我如何搜索LDAP中的用戶使用匿名綁定?