Showing posts with label LDAP. Show all posts
Showing posts with label LDAP. Show all posts

Wednesday, July 4, 2007

Show all objects of LDAP Server in PHP

Show all objects of LDAP Server in PHP

<?php
//$ldapServer = "ldap://111.222.111.222:389";

$ldapServer = '111.222.111.222';
$ldapBase = 'DC=abc,DC=com';
$ldapConn = ldap_connect($ldapServer);
if (!$ldapConn)
{
  die('Cannot Connect to LDAP server');
}
$ldapBind = ldap_bind($ldapConn);
if (!$ldapBind) {
  die('Cannot Bind to LDAP server');
}
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapSearch = ldap_search($ldapConn, $ldapBase, "(cn=*)");
$ldapResults = ldap_get_entries($ldapConn, $ldapSearch);
for ($item = 0; $item < $ldapResults['count']; $item++) {
  for ($attribute = 0; $attribute < $ldapResults[$item]['count']; $attribute++) {
    $data = $ldapResults[$item][$attribute];
    echo $data.":&nbsp;&nbsp;".$ldapResults[$item][$data][0]."<br>";
  }
  echo '<hr />';
}
?>