PHP LDAP 连接

PHP LDAP Connection

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

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

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

用户搜索基础: ou=CompanyUsers

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

组搜索基础: OU=Security,OU=CompanyGroups

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

群组成员资格:群组成员资格属性=memberOf

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

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

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

以下是 linux 基本 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"; 

   }
} 

?>
============================