我正在嘗試執行ldap授權,然後再次檢查組中的成員身份。系統是一臺運行php 5.3.10的Ubuntu機器,用於對Server2008 R2 Active Directory進行身份驗證。我似乎無法讓ldap_search()工作。我從jExplore中提取了DN,所以我很確定DN是正確的。 ldap_bind可以在另一個函數中使用證書,所以我確信服務器和用戶名/密碼是有效的。錯誤:php Active Directory查找
PHP Warning: ldap_search(): Search: Operations error in /var/www/zzz.php on line 28
代碼:
$ldap = ldap_connect('ldap://xxx.xxx');
$admins = $auth['admin'];
// User not logged in, user level '0'
if (!isset($user))
{
return 0;
}
// DN
$group_dn = 'CN=IT Employees,OU=groups,OU=users,OU=xxx,DC=xxx,DC=xxx';
// Filter
$filter = '(sAMAccountName=' . $user . ')';
// Attributes
$attr = array("memberof","givenname");
echo $group_dn.' '.$filter.' '.$attr.'<br />';
// Check if the user is a member of the Admin Group
$SubGroups = ldap_search($ldap, $group_dn, $filter, $attr); //Search the admin group for user.
$debug = ldap_get_entries($ldap, $SubGroups);
echo $debug['count'];
if ($debug['count']>>0)
{
// Yep, you are set admin. (User level 2)
echo "Admin Set<br />";
return 2;
}
else
{
// Failure. Thou art a normal user. (User level 1)
echo "Admin Denied<br />";
return 1;
}
}
也許檢查$ LDAP是一個有效的資源? – ficuscr
此問題的答案應該可以幫助您:http://stackoverflow.com/questions/6222641/how-to-php-ldap-search-to-get-user-ou-if-i-dont-know-the -ou-for-base-d –
感謝Matthew的建議,但它沒有解決它。 :( –