开发者

Problem with getting the username in Active Dirctory using PHP

开发者 https://www.devze.com 2023-02-22 06:19 出处:网络
I am connecting to an Active Dirctroy server using the following code: $ldapHost = \"ldap://XXX.com\";

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

精彩评论

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

关注公众号