【问题标题】:PHP LDAP ConnectionPHP LDAP 连接
【发布时间】:2016-11-01 19:54:19
【问题描述】:

我收到了以下 LDAP 参数,但不确定如何在 PHP 中建立连接。我不确定每组参数使用哪个 PHP 函数。这是给我的参数:

服务器: ldaps://the_server.com:636

根 DN: dc=the_info,dc=more_info,dc=com

用户搜索库: ou=CompanyUsers

用户搜索过滤器: sAMAccountName={0}

组搜索库: OU=Security,OU=CompanyGroups

组搜索过滤器: cn={0}

群组成员身份:群组成员身份属性 = memberOf

显示名称 LDAP 属性:显示名称

电子邮件地址 LDAP 属性:邮件

如果有人可以为我提供一个 php 脚本,那就太好了!这是我第一次使用 LDAP,但仍然不了解所有这些参数。

【问题讨论】:

    标签: php active-directory server ldap base


    【解决方案1】:

    以下是 linux base ldap 的工作代码。 可能对你有帮助。

    <?php
    $username = 'uid=amitkawasthi,ou=CompanyUsers,dc=the_info,dc=more_info,dc=com'; 
    $password= 'test'; 
    $ds=ldap_connect("the_server.com, 636"); 
    echo $ds;
    if ($ds) { 
       echo "Binding ..."; 
       $r=ldap_bind($ds, $username, $password); 
       if ($r)
       { 
       $sr=ldap_search($ds,"ou=CompanyUsers,dc=the_info,dc=more_info,dc=com", "uid=amitkawasthi");   
       $entry = ldap_first_entry($ds, $sr); 
       $attrs = array(); 
       $attribute = ldap_first_attribute($ds,$entry,$identifier); 
       while ($attribute) { 
         $attrs[] = $attribute; 
         $attribute=ldap_next_attribute($ds,$entry,$identifier); 
         } 
        echo count($attrs) . " attributes held for this entry:<p>"; 
    
        $ldapResults = ldap_get_entries($ds, $sr); 
    //for ($item = 0; $item < $ldapResults['count']; $item++) { 
      // for ($attribute = 0; $attribute < $ldapResults[$item]['count'];                  $attribute++) { 
        //echo  $data = $ldapResults[$item][$attribute]; 
        echo  $data = $ldapResults[0][$attribute]; 
        echo $data.":&nbsp;&nbsp;".$ldapResults[0][$data][0]."<br>";             
       //} 
    ///echo '<hr />'; 
    
       echo "OK"; 
       }
       else
       {
       echo "Fail"; 
    
       }
    } 
    
    ?>
    ============================
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多