Hey guys 🙂
Below is my succesfully working code to retrieve a full list of staff and there contact details from my windows 2003 active directory via ldap. However, currently it sorts into goups depending on what letter the staff members last name is so all latnames starting with A go under the A group kind of thing and thats how it lists them.
However i want to also say have Group A sorted by last name again.. using ldap_sort, so that all the group A are in alphabeticall order at the momment all the A's are listed togther but not in alphabetical order.
So as a test i added ldap_sort($ad, $sr, "sn"); ( in the code below its commented out) now i my test webserver which is apache latest running php 5 it works perfectly, but on the actaul server its meant to run in which is IIS on win2k3 server running php 4.3 it jsut stalls the script and the script sits there trying to load but doesnt.
So what im asking is what could cause this and is there a solution besides changing to apache and php 5 😛 ????
Hope you guys can help!
<?php
// LDAP Server Connection Strings
// Designate a few variables
$host = "ldap://myserverlol";
$user = "username";
$pswd = "password";
$ad = ldap_connect($host)
or die( "Could not connect!" );
// Set version number
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3)
or die ("Could not set ldap protocol");
// Create the DN
$dn = "OU=Staff, DC=my, DC=company";
$attrs = array("mail","telephonenumber","department","facsimiletelephonenumber","mobile","title","cn","sn");
// If LDAP server exists then bind to server
if ($ad) {
$r=ldap_bind($ad, $user, $pswd);
for($search = "A"; $search != "AA"; $search++){
print("<tr><td colspan=6><strong>$search</strong></td></tr>");
$filter = "(|(sn=$search*))";
//Perform LDAP Search
$sr=ldap_search($ad, $dn, $filter, $attrs);
//ldap_sort($ad, $sr, "sn"); //sorts results by surname
$info = ldap_get_entries($ad, $sr);
for ($i=0; $i<$info["count"]; $i++) {
if($info[$i]["telephonenumber"][0] != 999){
echo "<tr valign=top><td nowrap>". @$info[$i]["cn"][0]."</td>";
if(!$info[$i]["title"][0])
{
echo "<td> </td>";
} else {
echo "<td>". @$info[$i]["title"][0]."</td>";
};
if(!$info[$i]["department"][0])
{
echo "<td> </td>";
} else {
echo "<td>". @$info[$i]["department"][0]."</td>";
};
if(!$info[$i]["telephonenumber"][0])
{
echo "<td> </td>";
} else {
echo "<td class='padNumber'>". @$info[$i]["telephonenumber"][0]."</td>";
};
if(!$info[$i]["facsimiletelephonenumber"][0])
{
echo "<td> </td>";
} else {
echo "<td class='padNumber'>". @$info[$i]["facsimiletelephonenumber"][0]."</td>";
};
if(!$info[$i]["mobile"][0])
{
echo "<td> </td></tr>";
} else {
echo "<td class='padNumber'>". @$info[$i]["mobile"][0]."</td></tr>";
};
if($info[$i]["mail"][0])
{
echo "<tr><td class='secondRow'> </td><td class='secondRow' colspan=5><a href=mailto:". @$info[$i]["mail"][0] .">". @$info[$i]["mail"][0] ."</a></td></tr>";
};
}
}
}
}
ldap_unbind($ad);
?>