[英]LDAP in PHP get current user details
我可以使用AD和PHP進行身份驗證,但我的問題是我不知道如何獲取當前用戶的顯示名或cn詳細信息。 來自php.com的此示例代碼可以很好地進行身份驗證,但是現在我需要詳細信息有人幫忙嗎?
// using ldap bind
$ldaprdn = 'uname'; // ldap rdn or dn
$ldappass = 'password'; // associated password
// connect to ldap server
$ldapconn = ldap_connect("ldap.example.com")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed...";
}
}
將搜索請求發送到服務器並解釋響應。 搜索請求(由ldap_search
封裝在PHP中)至少包含以下內容:
one
, subtree
或base
:搜索的深度 cn
, displayName
以及處理所需的任何其他屬性的位置: 認證之前,將要認證的值存儲在會話變量中。 如果驗證成功,則使用會話值顯示。
如果身份驗證失敗,請清除會話值,然后嘗試再次提交登錄表單。
以下是將值分配給ZF2中的會話變量的示例代碼:
$session = new Container('base');
$this->session->offsetSet('username', $username);
並獲取會話值:
$sesUserName = $this->session->offsetGet('username');
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.