Skip to content

Instantly share code, notes, and snippets.

@jacricelli
Created July 12, 2020 07:00
Show Gist options
  • Save jacricelli/499abb4d55a588c69b31ec52327d02d7 to your computer and use it in GitHub Desktop.
Save jacricelli/499abb4d55a588c69b31ec52327d02d7 to your computer and use it in GitHub Desktop.
LDAP Entry
<?php
$adServer = "ldap://ip";
$ldap = ldap_connect($adServer);
$username = '';
$password = '';
$ldaprdn = 'DOMAIN' . "\\" . $username;
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap, LDAP_OPT_NETWORK_TIMEOUT, 10);
$bind = ldap_bind($ldap, $ldaprdn, $password);
if ($bind) {
$attributes = array();
$attributes[] = 'givenname';
$attributes[] = 'mail';
$attributes[] = 'memberof';
$attributes[] = 'samaccountname';
$attributes[] = 'sn';
$result = ldap_search($ldap, "OU=Users,DC=domain,DC=com", "(&(objectClass=person)(samaccountname=$username))", $attributes);
$entry = ldap_get_entries($ldap, $result);
var_dump($entry);
@ldap_close($ldap);
} else {
echo "Bad!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment