<?php $host = "bbs-svr-001.bbarrington.internal"; $port = "389"; $tls = false; $dn = 'USER@bbarrington.internal'; $pass = 'PASS'; $base = "ou=bbs,ou=establishments,dc=bbarrington,dc=internal"; $scope = "sub"; $filter = "samaccountname=*"; echo "<h3>LDAP query test</h3>\n"; echo "Connecting ...\n"; $ds=ldap_connect($host, $port); echo "connect result is " . $ds . "<br />\n"; if ($ds) { echo "Binding ...\n"; if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) { echo "Failed to setup LDAP protocol to 3 - Start TLS not support\n"; exit; } echo "Starting TLS...\n"; if (!ldap_start_tls($ds)) { echo "Cannot start TLS\n"; } $r=ldap_bind($ds, $dn, $pass); echo "Bind result is " . $r . "<br />\n"; echo "Searching for $filter ..."; $sr=ldap_search($ds, $base, $filter); echo "Search result is " . $sr . "<br />\n"; echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "<br />\n"; echo "Getting entries ...<p>\n"; $info = ldap_get_entries($ds, $sr); echo "Data for " . $info["count"] . " items returned:<p>\n"; for ($i=0; $i<$info["count"]; $i++) { echo "dn is: " . $info[$i]["dn"] . "<br />\n"; //echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />\n"; //echo "first email entry is: " . $info[$i]["mail"][0] . "<br /><hr />\n\n"; } echo "Closing connection\n"; ldap_close($ds); } else { echo "<h4>Unable to connect to LDAP server</h4>"; } ?>