需要在active-directory中显示用户的信息
The following code will search for the user within the domain controller, but I want to display the info of each thing noted within the justthese variable: "displayname","mail","samaccountname","sn","givenname","department","telephonenumber"
$dn = "dc=xxx,dc=xxx";
$justthese = array("displayname","mail","samaccountname","sn","givenname","department","telephonenumber");
$sr=ldap_search($ldapconn, $dn,'SAMAccountName=username', $justthese);
$info = ldap_get_entries($ldapconn, $sr);
echo "<h3>".$info["count"]." entries returned</h3>";
foreach($justthese as $key=>$value){
print '<p><strong>'.$value.'</strong></p>';
}
It displays each item within the $justthese array, I want to display the info for that user for each thing noted in $justthese array.
Right now it outputs it like this:
displayname
samaccountname
sn
givenname
department
telephonenumber
I want it to have the actual data to the right of it, which I know I am doing something wrong with the foreach loop, any help is appreciated.
So it'd look like this
displayname Chuck
mail chuck@norris.com
samaccountname chucknorris
sn chuckisthebest
givenname Chuck Norris
department Security
telephonenumber 555-555-5555
以下代码将搜索域控制器中的用户,但我想显示每个注意事项的信息 在justthese变量中:“displayname”,“mail”,“samaccountname”,“sn”,“givenname”,“department”,“telephonenumber” p>
$ dn =“ dc = xxx,dc = xxx“;
$ justthese = array(”displayname“,”mail“,”samaccountname“,”sn“,”givenname“,”department“,”telephonenumber“);
$ sr = ldap_search($ ldapconn,$ dn,'SAMAccountName = username',$ justthese);
$ info = ldap_get_entries($ ldapconn,$ sr);
echo“&lt; h3&gt;”。$ info [ “count”]。“条目返回&lt; / h3&gt;”;
foreach($ justthese as $ key =&gt; $ value){
print'&lt; p&gt;&lt; strong&gt;'。$ value。'&lt ; / strong&gt;&lt; / p&gt;';
}
code> pre>
它显示$ justthese数组中的每个项目,我想显示该用户的信息 对于$ justthese数组中注明的每一件事。 p>
现在它输出如下: p>
displayname p>
邮件 p>
samacc ountname P>
SN P>
给定名称 P>
系 P>
telephonenumber
我希望它拥有它右侧的实际数据,我知道我对foreach循环做错了,任何帮助都表示赞赏。 p>
所以它看起来像这样 p>
displayname Chuck p>
mail chuck@norris.com p>
samaccountname chucknorris p>
sn chuckisthebest p>
givenname Chuck Norris p>
部门安全 p>
\ n
电话号码555-555-5555 p>
div>
Assuming your $info
returns just one user: (though you should probably loop through the user array or at least print_r
it to see what it's returning)
foreach($justthese as $key=>$value){
print '<p><strong>'.$value.' ' . (isset($info[0][$value]) ? $info[0][$value] : 'empty') . '</strong></p>';
}
Aren't you simply looping trough the wrong array? You probably want to loop trough $info I think?