/ Published in: PHP
Expand |
Embed | Plain Text
<?php // basic sequence with LDAP is connect, bind, search, interpret search // result, close connection // using ldap bind $ldaprdn = 'userid'; // ldap rdn or dn $ldappass = 'password'; // associated password echo "<h3>LDAP query test</h3>"; echo "Connecting ..."; // connect to ldap server $ldapconn = ldap_connect("server_address") // Set some ldap options for talking to ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0); if ($ldapconn) { echo "Binding ..."; $r=ldap_bind($ldapconn,$ldaprdn,$ldappass); // this is an "anonymous" bind, typically // read-only access echo "Searching for (sn=S*) ..."; // Search surname entry $sr=ldap_search($ldapconn, "dc=lakecoe,dc=org", "sn=*"); echo "Getting entries ...<p>"; $info = ldap_get_entries($ldapconn, $sr); /*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 email entry is: " . $info[$i]["mail"][0] . "<br /><hr />"; }*/ echo "Closing connection"; ldap_close($ldapconn); } else { echo "<h4>Unable to connect to LDAP server</h4>"; } ?>
You need to login to post a comment.
