<bdo id='EqfLN'></bdo><ul id='EqfLN'></ul>

  • <legend id='EqfLN'><style id='EqfLN'><dir id='EqfLN'><q id='EqfLN'></q></dir></style></legend>

    <small id='EqfLN'></small><noframes id='EqfLN'>

    <i id='EqfLN'><tr id='EqfLN'><dt id='EqfLN'><q id='EqfLN'><span id='EqfLN'><b id='EqfLN'><form id='EqfLN'><ins id='EqfLN'></ins><ul id='EqfLN'></ul><sub id='EqfLN'></sub></form><legend id='EqfLN'></legend><bdo id='EqfLN'><pre id='EqfLN'><center id='EqfLN'></center></pre></bdo></b><th id='EqfLN'></th></span></q></dt></tr></i><div id='EqfLN'><tfoot id='EqfLN'></tfoot><dl id='EqfLN'><fieldset id='EqfLN'></fieldset></dl></div>

        <tfoot id='EqfLN'></tfoot>

        PHP LDAP获取作为组成员的成员的用户详细信息

        时间:2024-08-23

          <small id='s7lVN'></small><noframes id='s7lVN'>

            <tbody id='s7lVN'></tbody>
          <i id='s7lVN'><tr id='s7lVN'><dt id='s7lVN'><q id='s7lVN'><span id='s7lVN'><b id='s7lVN'><form id='s7lVN'><ins id='s7lVN'></ins><ul id='s7lVN'></ul><sub id='s7lVN'></sub></form><legend id='s7lVN'></legend><bdo id='s7lVN'><pre id='s7lVN'><center id='s7lVN'></center></pre></bdo></b><th id='s7lVN'></th></span></q></dt></tr></i><div id='s7lVN'><tfoot id='s7lVN'></tfoot><dl id='s7lVN'><fieldset id='s7lVN'></fieldset></dl></div>
          • <legend id='s7lVN'><style id='s7lVN'><dir id='s7lVN'><q id='s7lVN'></q></dir></style></legend>

              <tfoot id='s7lVN'></tfoot>

                • <bdo id='s7lVN'></bdo><ul id='s7lVN'></ul>
                  本文介绍了PHP LDAP获取作为组成员的成员的用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试创建一个 PHP 脚本,该脚本将返回我们 Active Directory 中特定组的每个成员的一些详细信息.

                  I'm trying to create a PHP script that will return some details of each member that is part of a specific group in our Active Directory.

                  我在连接和显示组成员的姓名 (CN) 时没有问题,但是在显示电话、电子邮件和用户名等详细信息时我就卡住了.

                  I have no problem connecting and display the names (CN) of the group members but when it comes to displaying details such as telephone, email and username I'm stuck.

                  这是我正在尝试的代码.谁能看到我做错了什么?

                  Here's my code I'm trying with. Can anyone see what I'm doing wrong?

                  <?php
                  $ldap_server = "AD_Server.domain.pri:389";
                  $auth_user = "user@domain.pri";
                  $auth_pass = "password";
                  
                  $base_dn = "OU=IM Groups,OU=GLOBAL,DC=domain,DC=pri";
                  $filter = "(&(objectCategory=user)(memberOf=IM-ALL_USERS))";
                  
                  // connect to server
                  if (!($connect=@ldap_connect($ldap_server))) {
                       die("Could not connect to ldap server");
                  }
                  
                  // bind to server
                  if (!($bind = ldap_bind($connect, $auth_user, $auth_pass))) {
                       die("Unable to bind to server");
                  }
                  
                  // search active directory
                  if (!($search = ldap_search($connect, $base_dn, $filter))) {
                       die("Unable to search ldap server");
                  }
                  
                  $number_returned = ldap_count_entries($connect,$search);
                  $info = ldap_get_entries($connect, $search);
                  
                  echo "The number of entries returned is ". $number_returned."<p>";
                  
                  for ($i=0; $i<$info["count"]; $i++) {
                     echo "Name is: ". $info[$i]["givenname"][0]."<br>";
                     echo "Display name is: ". $info[$i]["displayname"][0]."<br>";
                     echo "Email is: ". $info[$i]["mail"][0]."<br>";
                     echo "Telephone number is: ". $info[$i]["telephonenumber"][0]."<p>";
                  }
                  ?>
                  

                  推荐答案

                  使用 Sam J Levy.

                  这是最终有效的代码.

                  <?php
                  
                  function explode_dn($dn, $with_attributes=0)
                  {
                      $result = ldap_explode_dn($dn, $with_attributes);
                      foreach($result as $key => $value) $result[$key] = preg_replace("/\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\1')).''", $value);
                      return $result;
                  }
                  
                  function get_members($group,$user,$password) {
                      $ldap_host = "LDAPSERVER";
                      $ldap_dn = "OU=some_group,OU=some_group,DC=company,DC=com";
                      $base_dn = "DC=company,DC=com";
                      $ldap_usr_dom = "@company.com";
                      $ldap = ldap_connect($ldap_host);
                  
                      ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION,3);
                      ldap_set_option($ldap, LDAP_OPT_REFERRALS,0);
                  
                      ldap_bind($ldap, $user . $ldap_usr_dom, $password);
                      $results = ldap_search($ldap,$ldap_dn, "cn=" . $group);
                      $member_list = ldap_get_entries($ldap, $results);
                  
                      $dirty = 0;
                      $group_member_details = array();
                  
                      foreach($member_list[0]['member'] as $member) {
                          if($dirty == 0) {
                              $dirty = 1;
                          } else {
                              $member_dn = explode_dn($member);
                              $member_cn = str_replace("CN=","",$member_dn[0]);
                              $member_search = ldap_search($ldap, $base_dn, "(CN=" . $member_cn . ")");
                              $member_details = ldap_get_entries($ldap, $member_search);
                              $group_member_details[] = array($member_details[0]['givenname'][0],$member_details[0]['sn'][0],$member_details[0]['telephonenumber'][0],$member_details[0]['othertelephone'][0]);
                          }
                      }
                      ldap_close($ldap);
                      return $group_member_details;
                  }
                  
                  // Specify the group from where to get members and a username and password with rights to query it
                  $result = get_members("groupname","username","password");
                  
                  // The following will create an XML file with the details from $group_member_details
                  $xml = simplexml_load_string("<?xml version='1.0'?>
                  <AddressBook></AddressBook>");
                  $version = $xml->addChild('version', '1');
                  
                  foreach($result as $e) {
                      $contact = $xml->addChild('Contact');
                      $contact->addChild('FirstName', $e[0]);
                      $contact->addChild('LastName', $e[1]);
                      $phone = $contact->addChild('Phone');
                      if ($e[3] == '') {
                                  $phone->addChild('phonenumber', '0');
                          } else {
                                  $phone->addChild('phonenumber', $e[3]);
                          }
                      $phone->addChild('accountindex', '0');
                      $phone = $contact->addChild('Phone');
                      if ($e[2] == '') {
                          $phone->addChild('phonenumber', '0');
                      } else {
                          $phone->addChild('phonenumber', $e[2]);
                      }
                      $phone->addChild('accountindex', '1');
                      $contact->addChild('Group', '0');
                      $contact->addChild('PhotoUrl', 'empty');
                  }
                  
                  $xml->asXML('phonebook.xml');
                  
                  ?>
                  

                  这篇关于PHP LDAP获取作为组成员的成员的用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:即使我编辑了 php.ini 并且 php_ldap.dll 在正确的位置,也无法启用 PHP LDAP? 下一篇:LDAP 和 PHP 连接失败

                  相关文章

                  • <bdo id='ELPiw'></bdo><ul id='ELPiw'></ul>
                    <i id='ELPiw'><tr id='ELPiw'><dt id='ELPiw'><q id='ELPiw'><span id='ELPiw'><b id='ELPiw'><form id='ELPiw'><ins id='ELPiw'></ins><ul id='ELPiw'></ul><sub id='ELPiw'></sub></form><legend id='ELPiw'></legend><bdo id='ELPiw'><pre id='ELPiw'><center id='ELPiw'></center></pre></bdo></b><th id='ELPiw'></th></span></q></dt></tr></i><div id='ELPiw'><tfoot id='ELPiw'></tfoot><dl id='ELPiw'><fieldset id='ELPiw'></fieldset></dl></div>
                    <legend id='ELPiw'><style id='ELPiw'><dir id='ELPiw'><q id='ELPiw'></q></dir></style></legend>

                    1. <small id='ELPiw'></small><noframes id='ELPiw'>

                    2. <tfoot id='ELPiw'></tfoot>