Created
June 28, 2010 22:21
-
-
Save seyyah/456454 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// basic sequence with LDAP is connect, bind, search, interpret search | |
// result, close connection | |
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); | |
echo "<h3>LDAP query test</h3>"; | |
echo "Connecting ..."; | |
$ds = ldap_connect("192.168.56.102", "389"); // must be a valid LDAP server! | |
echo "connect result is " . $ds . "<br />"; | |
if ($ds) { | |
echo "Binding ..."; | |
$r = ldap_bind($ds, "cn=admin,dc=debuntu,dc=local", "secret"); | |
echo "Bind result is " . $r . "<br />"; | |
echo "Searching for (cn=*) ..."; | |
// Search | |
$sr=ldap_search($ds, "ou=People,dc=debuntu,dc=local", "cn=*"); | |
echo "Search result is " . $sr . "<br />"; | |
echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "<br />"; | |
echo "Getting entries ...<p>"; | |
$info = ldap_get_entries($ds, $sr); | |
echo "Data for " . $info["count"] . " items returned:<p>"; | |
for ($i=0; $i<$info["count"]; $i++) { | |
echo "dn is: " . $info[$i]["dn"] . "<br />"; | |
echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />"; | |
echo "first uid entry is: " . $info[$i]["uid"][0] . "<br /><hr />"; | |
} | |
echo "Closing connection"; | |
ldap_close($ds); | |
} else { | |
echo "<h4>Unable to connect to LDAP server</h4>"; | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment