簡體   English   中英

PHP中的LDAP獲取當前用戶詳細信息

[英]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中)至少包含以下內容:

  • 基本對象(或某些文檔中的基本DN):搜索結果中不會考慮任何優於基本DN的對象
  • 搜索范圍: onesubtreebase :搜索的深度
  • 過濾器:用於過濾(縮小)結果池
  • 要求的屬性:這是LDAP客戶端應在其中放置cndisplayName以及處理所需的任何其他屬性的位置:

也可以看看

認證之前,將要認證的值存儲在會話變量中。 如果驗證成功,則使用會話值顯示。

如果身份驗證失敗,請清除會話值,然后嘗試再次提交登錄表單。

以下是將值分配給ZF2中的會話變量的示例代碼:

  $session = new Container('base');                     
  $this->session->offsetSet('username', $username);

並獲取會話值:

  $sesUserName = $this->session->offsetGet('username'); 

我希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM