Reputation: 8678
When connecting to an LDAP server, you can provide multiple hosts separated by a space:
$resource = ldap_connect('ldap://dc01.corp.acme.org ldap://dc02.corp.acme.org');
But is there a way to retrieve which one is actually being used after a successful bind?
Upvotes: 1
Views: 167
Reputation: 2869
No real good way unfortunately. There is an AD specific way via checking the RootDSE:
$con = ldap_connect('ldap://dc1 ldap://dc2');
ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
ldap_bind($con, '[email protected]', 'correct-horse-battery-staple');
$sr = ldap_read($con, '', 'objectClass=*', ['dnshostname']);
$entry = ldap_get_entries($con, $sr);
// This is the DC we are on...
echo $entry[0]['dnshostname'][0];
Upvotes: 1