AD-X
AD-X copied to clipboard
Automatically attempt to detect domain server for Windows
When running php scripts on a Windows machine that is joined to a domain, there are some environment variables which could tell me the DNS name of the domain the computer is joined to. That way, users would not have to know the exact server address, just call Link::connect()->bind('user', 'pass'); and be done with it.
There are two environment variables I found that reference the domain that a computer is joined to. For the typical example of the "contoso.com" domain: USERDNSDOMAIN = CONTOSO.COM USERDOMAIN = CONTOSO
You can then query DNS for "contoso.com" and it will return the IPs of the domain controllers, though some of them may be in different AD sites if the network is separated over WAN links.