Home | 문태준 | 시스템어드민 메일링 | Sys Admin 세미나

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
$USER_ID = "USER@MYDOMAIN";
$PWD = "PASSWORD";
$dn = "OU=Users,DC=MYDOMAIN";
$ad = ldap_connect("ldap://SERVER.MYDOMAIN")
      or die("Couldn't connect to AD!");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
$bd = ldap_bind($ad,$USER_ID,$PWD)
      or die("Couldn't bind to AD!");
$filter = "samaccountname=SOMEREALUSERNAME"; //real user name
$result = ldap_search($ad, $dn,$filter);
$entry=ldap_first_entry($ad,$result);
$name = ldap_get_values($ad, $entry, "samaccountname");
print_r($name); 

$hoursbinary=ldap_get_values_len($ad,$entry,"logonhours");
$hourshex=bin2hex($hoursbinary[0]);
print "hours: ".$hourshex."<br>"; 

 

기타

검색방법이 좀 다르기에 추가 정보를 입력한다.
for 과 ldap_next_entry 를 이용하여 전체 데이터를 처리하면 될 것이다.

http://www.php.net/manual/en/function.ldap-first-entry.php

Code Block
Here's a nice way to user ldap_first_entry,ldap_next_entry.

$res = ldap_search($ldapc,$searchroot,$filter,$attributes);
for ($entryID=ldap_first_entry($ldapc,$res);
            $entryID!=false;
            $entryID=ldap_next_entry($ldapc,$entryID))
{
// Do stuff with the $entryID.
$values = ldap_get_values($ldapc,$entryID,'uid');
}