views:

43

answers:

2

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

mail

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 [email protected]

samaccountname chucknorris

sn chuckisthebest

givenname Chuck Norris

department Security

telephonenumber 555-555-5555

A: 

Aren't you simply looping trough the wrong array? You probably want to loop trough $info I think?

hoppa
I am trying to find the user within AD, check what group they're a member of, because I am trying to restrict access by group, for example there will be pages only accessible to faculty, staff, students - so I need to figure out what group that user belongs to, then run it thru a conditional to make sure their group matches up with the group that is specified for that page they are currently on, if false, it denies them access.
Brad
A: 

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>';
}
Aaron W.