开发者

Problem with getting the username in Active Dirctory using PHP

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜