I am connecting to an Active Dirctroy server using the following code:
$ldapHost = "ldap://XXX.com";
$ldapPort = "389";
$ldapUser ="XXX@XXX.com";
$ldapPswd ="XXX";
$ldapLink =ldap_connect($ldapHost, $ldapPort)
or die("Can't establish LDAP connection");
ldap_bind($ldapLink,$ldapUser,$ldapPswd)
or die("Can't bind to server.");
It's working well, but how can I print the username? That is, any time a user visits the page, I want to print the user'开发者_Python百科s name that's stored in Active Directory.
You just need to use ldap_search()
in order to retreive the attributes called sn
and givenName
.
You have to search in the subtree
from dc=xxxx,d=com
with a LDAP filter like (userPrincipalName=$ldapUser)
.
精彩评论