"1.2.840.113556.1.4.1339", "iscritical" => TRUE ); if (ldap_set_option($ds, LDAP_OPT_SERVER_CONTROLS, array($ctrl))) { echo " Turned on limit_scope\n"; } else { echo " Unable to turn on limit_scope\n"; } } else { echo " You must use LDAPv3 protocol with limit_scope option.\n"; } } else { echo " Not using limit_scope option.\n"; } echo "\nReading LDAP base:\n"; if ($sr = ldap_read($ds,'',"(objectclass=*)")) { $info = ldap_get_entries($ds, $sr); echo " namingContexts:\n"; if (isset($info[0]['namingcontexts'])) { for ($i=0; $i<$info[0]['namingcontexts']['count']; $i++) { echo ' ' . $i .': ' . $info[0]['namingcontexts'][$i] . "\n"; } } else { echo " unavailable\n"; } } else { echo " Unable to read LDAP base.\n"; } echo "\n"; echo "Authentication:\n"; echo " Binding"; if ($ldap_binddn!='') { echo " with authenticated bind ...\n"; $r = ldap_bind($ds,$ldap_binddn,$ldap_bindpw); } else { echo " with anonymous bind ...\n"; $r=ldap_bind($ds); } echo " Bind result - "; var_dump($r); echo "\n"; echo "\n"; echo "Search:\n"; echo " Searching for (mail=*) ...\n"; // Search for mail entries if ($sr=ldap_search($ds, $ldap_basedn, "(mail=*)")) { echo " Search result - "; var_dump($sr); echo "\n"; echo " Number of entries: " . ldap_count_entries($ds, $sr) . "\n"; echo " Getting entries ...\n"; $info = ldap_get_entries($ds, $sr); echo " Data for " . $info["count"] . " items returned:\n"; for ($i=0; $i<$info["count"]; $i++) { echo " dn is: " . $info[$i]["dn"] . "\n"; if (isset($info[$i]["cn"][0])) { echo " first cn entry is: " . $info[$i]["cn"][0] . "\n"; } else { echo " cn attribute is not available."; } echo " first email entry is: " . $info[$i]["mail"][0] . "\n------\n"; } } else { echo " LDAP search failed.\n"; } echo "\n"; echo "Closing connection\n"; ldap_close($ds); } else { echo "Unable to connect to LDAP server\n"; } ?>