Hello Everyone,
My company has asked me to put a company directory on our intranet site
and I'm trying to use php to extract the users from our active
directory server. I've got everything working, however, when the list
of users is shown in the output, it seems to display the users in the
order their accounts were created, with Administrator obviously being
first. What do you think would be the best way to get the list to be
sorted by lastname (sn), based on the coding below. usort? ldap_sort?
Not really too familiar with using php and ldap or active directory.
Any help would be appreciated, thank you!
<?php
$ldap_server = "ldap://ourldap";
$auth_user = "user";
$auth_pass = "pass";
// Set the base dn to search the entire directory.
$base_dn = "ou=staff, dc=ourldap, dc=com";
// Show People
$filter = "(&(objectClass=user)(objectCategory=person)(cn=*) )";
// connect to server
if (!($connect=@ldap_connect($ldap_server))) {
die("Could not connect to ldap server");
}
// bind to server
if (!($bind=@ldap_bind($connect, $auth_user, $auth_pass))) {
die("Unable to bind to server");
}
// search active directory
if (!($search=@ldap_search($connect, $base_dn, $filter))) {
die("Unable to search ldap server");
}
$number_returned = ldap_count_entries($connect,$search);
$info = ldap_get_entries($connect, $search);
echo "The number of entries returned is ". $number_returned."<p>";
for ($i=0; $i<$info["count"]; $i++) {
// echo "Name is: ". $info[$i]["name"][0]."<br>";
echo "Name: ". $info[$i]["sn"][0].", ".
$info[$i]["givenname"][0]."<br>";
echo "Email: ". $info[$i]["mail"][0]."<br>";
echo "Title: ". $info[$i]["description"][0]."<br>";
echo "Ext.: ". $info[$i]["telephonenumber"][0]."<br>";
echo "Website.: ". $info[$i]["wwwhomepage"][0]."<p>";
}
ldap_close($connect);
?>