Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $domain = 'acme.local';
- $username = 'aduser';
- $password = 'replaceWithPassword';
- $ldapconfig['host'] = '192.168.21';
- $ldapconfig['port'] = 389;
- $ldapconfig['basedn'] = 'dc=acme,dc=local';
- $ldap_dn = "DC=acme,DC=local";
- //print_r($ldapconfig);
- $ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
- ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
- if ($ds) {
- echo("ldap connect completed\n");
- ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
- $bind=ldap_bind($ds, $username.'@'.$domain, $password);
- if ($bind) {
- echo "LDAP bind successful...$bind <br />";
- $attributes= array( "sn", "givenname", "mail", "samaccountname");
- $filter = '(&(objectCategory=person)(samaccountname=*))';
- $results = ldap_search($ds, $ldap_dn, $filter, $attributes);
- if ($retval) {
- echo("Login correct <br />");
- $info = ldap_get_entries($ds, $results);
- print_r($info);
- for ($i=0; $i<$entries["count"]; $i++)
- {
- echo $entries[$i]["displayname"]
- [0]."(".$entries[$i]["l"][0].")<br />";
- }
- } else {
- echo("Login incorrect <br />".ldap_error($retval));
- }
- }else {
- echo "ERROR: LDAP bind failed...<br />";
- }
- ldap_unbind($bind);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement