Advertisement
Guest User

test ldap

a guest
Sep 7th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2. $username = 'cn=opendcim bind,ou=opendcim,ou=Applications,ou=Services,dc=domain,dc=com';
  3. $password = 'test';
  4. $server = 'domain.com';
  5.  
  6. $ldapConn = ldap_connect($server);
  7. if (!$ldapConn) {
  8.     exit('Connection failed');
  9. }
  10.  
  11. // Help talking to AD
  12. ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
  13. ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0);
  14.  
  15. $ldapBind = ldap_bind($ldapConn, $username, $password);
  16. if (!$ldapBind) {
  17.     exit("\nBinding failed\n\n");
  18. }
  19.  
  20. printf("\nHello from LDAP\n\n");
  21.  
  22. //$filter = "(&(objectClass=group)(member=CN=Luis Caldeira,OU=Ent Admins,OU=Services,DC=domain,DC=com))";
  23. $filter = "(&(userprincipalname=user@domain.com)(memberOf:1.2.840.113556.1.4.1941:=cn=siteAdmin,ou=opendcim,ou=Applications,ou=Services,dc=domain,dc=com))";
  24.  
  25.  
  26. $search = ldap_search($ldapConn,"DC=domain,DC=com",$filter);
  27. $results  = ldap_get_entries($ldapConn,$search);
  28.  
  29.  
  30. var_dump($results);
  31.  
  32. // This is where you can do your work
  33.  
  34. ldap_close($ldapConn);
  35.  
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement