2010-02-10 21 views

回答

8

如果您激活mod_authnz_ldap模塊模塊和配置部分是這樣的:

<Directory /var/www/yoursite/> 
    AuthName "LDAP Secured" 
    AuthType Basic 
    AuthLDAPUrl "ldap://your.ldap.server:389/dc=example,dc=com?sAMAccountName" 
    AuthLDAPBindDN "[email protected]" 
    AuthLDAPBindPassword "secret" 
    AuthBasicProvider ldap 
    AuthzLDAPAuthoritative off 
    Require valid-user 
</Directory> 

然後在你的PHP代碼,你可以獲取用於登錄如用戶ID這:

<?php 
    $userId = $_SERVER['AUTHENTICATE_SAMACCOUNTNAME']; 
    echo "User ID: " . $userId; 
<? 

您在AuthL中指定的任何LDAP屬性DAPUrl指令可以通過這種方式獲得(以AUTHENTICATE_爲前綴,然後以全部大寫形式附加屬性名稱)。您可以通過用逗號分隔它們來添加更多屬性,但只有第一個屬性將用於身份驗證。進一步的細節見http://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html#exposedhttp://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html#authldapurl

相關問題