首頁 >後端開發 >php教程 >LDAP與PHP的要點

LDAP與PHP的要點

Jennifer Aniston
Jennifer Aniston原創
2025-02-19 10:34:12288瀏覽

Essentials of LDAP with PHP

需要一種直接的方法來存儲地址簿風格的數據和網絡信息以及任何結構化數據嗎? LDAP是一種可以追溯到1993年的技術,它提供了解決方案。雖然缺乏諸如Node.js和Go之類的新技術的“酷”因素,但其功能仍然很重要。

密鑰概念:

1993年在密歇根大學創建的LDAP(輕量級目錄訪問協議)是用於管理目錄服務的Internet協議。 它有效地存儲和管理通訊錄信息,網絡詳細信息和其他有組織的數據。 >
    > OpenLDAP是一種廣泛使用的開源LDAP服務器,是架構 - 敏捷的,這意味著它不會對數據結構或內容施加限制。 它可以使用命令行指令輕鬆地在基於Debian的系統上安裝和配置。
  • > PHP通過Zend-LDAP組件(來自Zend Framework 2)與LDAP服務器進行交互。這允許服務器查詢,連接管理和基本操作(例如數據庫搜索,輸入更新和刪除)。
  • >
  • ldap目錄採用層次樹狀結構,頂層稱為根或鹼。每個條目都包含屬性 - 每個類型和一個或多個值。
  • >
  • 理解LDAP:
LDAP或輕量級目錄訪問協議,歸功於1993年左右的密歇根大學,這要歸功於Tim Howes,Steve Kille,Colin Robbins和Wengyik Yeong的努力。 它本質上是舊的X.500協議(從1980年代)的互聯網友好版本,該協議最初是由國際電信聯盟(ITU)設計的,用於管理電話目錄。

“ LDAP”在技術上是指該協議,通常用於描述客戶端和服務器組件。 將其視為目錄服務器的SQL,即與LDAP啟用服務器進行交互的語言。 流行的LDAP服務器包括Microsoft的Active Directory(自Windows 2000以來集成到Windows)和開源OpenLDAP,我們將在此教程系列中使用。 OpenLDAP的靈活性允許多樣化的架構和數據存儲。

>

這第一部分涵蓋:

> OpenLDAP設置基礎知識。

加載數據記錄。

>使用Php。
  1. 基本術語:
  2. 在繼續前進,讓我們澄清一些關鍵術語:
  3. LDAP Term Description
    dn Distinguished Name: A record's unique identifier, similar to a primary key in relational databases.
    Directory Schema Defines the structure and constraints of the directory information.
    entry A record containing attributes that store data.
    attribute Similar to an associative array element or database column; specifies the data type, sorting rules, case-sensitivity, and other criteria.
    cn Common Name (e.g., "John Smith")
    sn Surname (e.g., "Smith")

    為了深入了解,請諮詢O'Reilly的LDAP指南或LDAP上的Wikipedia條目。

    > 設置LDAP服務器:

    >

    > OpenLDAP安裝和配置可能有些複雜。 這些步驟針對基於Debian的服務器進行了優化,目的是為了清晰和簡潔:>

    1. 安裝核心服務器和實用程序:

      <code class="language-bash">sudo apt-get install slapd ldap-utils</code>
    2. 配置服務器:

      <code class="language-bash">dpkg-reconfigure slapd</code>
      回答提示如下:

        >省略OpenLDAP服務器配置?
      • > DNS域名:
      • (或您的域)homestead.localdomain>
      • >您組織的名稱:(您的組織名稱)
      • >
      • 管理員密碼:(選擇一個強密碼)
      • 確認密碼:(重複密碼)
      • >
      • > BDB(Berkeley db)
      • >您是否希望在清除Slapd時刪除數據庫?
      • 移動舊數據庫?
      • 允許LDAPV2協議?

    驗證:>

    通過運行:

    檢查安裝

    <code class="language-bash">ldapsearch -x -b dc=homestead,dc=localdomain</code>
    如果遇到錯誤,請確保運行OpenLDAP:

    >

    <code class="language-bash">sudo netstat -tlnp | grep slapd</code>
    您應該看到輸出,表明slapd在端口389上聽

    填充數據庫:

    create

    帶有以下內容:

    > users.ldif

    加載數據:
    <code class="language-ldif">dn: cn=Sheldon Cooper,ou=People,dc=homestead,dc=localdomain
    cn: Sheldon Cooper
    objectClass: person
    objectClass: inetOrgPerson
    sn: Cooper
    
    dn: cn=Leonard Hofstadter,ou=People,dc=homestead,dc=localdomain
    cn: Leonard Hofstadter
    objectClass: person
    objectClass: inetOrgPerson
    sn: Hofstadter
    
    dn: cn=Howard Wolowitz,ou=People,dc=homestead,dc=localdomain
    cn: Howard Wolowitz
    objectClass: person
    objectClass: inetOrgPerson
    sn: Wolowitz
    
    dn: cn=Rajesh Koothrappali,ou=People,dc=homestead,dc=localdomain
    cn: Rajesh Koothrappali
    objectClass: person
    objectClass: inetOrgPerson
    sn: Koothrappali</code>

    (您將提示您輸入管理員密碼。)
    <code class="language-bash">ldapadd -x -W -D "cn=admin,dc=homestead,dc=localdomain" -f users.ldif</code>

    >使用:

    驗證記錄

    (php互動,連接到服務器,搜索,更新和刪除和刪除,將在隨後的部分中隨後的部分,由於長度限制。)

以上是LDAP與PHP的要點的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn