// make sure your host is the correct one
// that you issued your secure certificate to
$ldaphost = "";
$ldapport = "";
$ldapbasedn = "ou=box.net,dc=ad,dc=whirl,dc=net";
// using ldap bind
$ldaprdn = ''; // AD username
$ldappass = ''; // AD password
// connect to ldap server
$ldapconn = ldap_connect($ldaphost, $ldapport)
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding to ldap server
@ldap_bind($ldapconn, 'AD\\'.$ldaprdn, $ldappass) or die('Could not bind to AD');
// verify binding
if ($ldapconn) {
$attributes_ad = array("sAMAccountName", "displayName","description","cn","givenName","sn","mail","co","mobile","company");
$search = ldap_search($ldapconn, $ldapbasedn, "(sAMAccountName=$ldaprdn)", $attributes_ad) or die ("Error in search query");
$result = ldap_get_entries($ldapconn, $search);
print_r($result);
echo PHP_EOL;
} else {
echo "LDAP bind failed..." . PHP_EOL;
}
}
Monday, January 2, 2017
[PHP] AD/LDAP Integration
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment