简体   繁体   中英

PHP Recursive Search/LDAP

Doing a LDAP Search where i have to do a recursive search within the search to find another users attribute. Like an employee search and a manager search within the user's search.

Here is my code:

$id_array = preg_split("/[\s,]+/", $_POST["qlids"]);
    $ldap_connection = ldap_connect($ldaphost, $ldapport);
    if($ldap_connection) {
        $ldap_bind = ldap_bind($ldap_connection,$ldapuser,$ldappswd);
        if($ldap_bind) {
            for($i=0; $i<count($id_array); $i++) {
                if(trim($id_array[$i]) != '') {

                    $ldap_search = ldap_search($ldap_connection, "o=org,c=us", "uniqueid=" . strtolower($id_array[$i]));
                    $ldap_results = ldap_get_entries($ldap_connection, $ldap_search);

                    echo "<tr><td>" . $id_array[$i] . "</td>";
                    if($ldap_results["count"] > 0) {
                        if(trim($ldap_results[0]["cn"][0]) == '') {
                            echo "<td colspan=\"10\" class=\"rt\"><strong>ID Retired</strong></td>";
                        } 
                        else {
                            echo "<td>" . $ldap_results[0]["cn"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["mail"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["telephonenumber"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["l"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["st"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["co"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["resourceflag"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["businesssubgroupname"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["businessunitname"][0] . "</td>";
                            echo "<td>" . $ldap_results[0]["businesssubunitname"][0] . "</td>";
                            //echo "<td>" . $ldap_results[0]["sponsorid"][0] . "</td>";
                            for ($ii=0; $ii<count($id_array); $ii++) {
                                $managersr=ldap_search($ldap_connection, 'o=org, c=us', "uniqueidentifier=".$ldap_results[0]["sponsorid"][0]."");  
                                $managerinfo = ldap_get_entries($ldap_connection, $managersr);
                                echo "<td>" . $managerinfo[$ii]["uniqueid"][0] . "</td>";
                                echo "<td>" . $managerinfo[$ii]["cn"][0] . "</td>";
                            }
                            //echo "<td>" . $ldap_results[0]["nickname"][0] . "</td>";
                        }
                    } 
                    else {
                        echo "<td colspan=\"10\" class=\"nf\">Not Found</td>";
                    }
                    echo "</tr>";
                }
            }
        } 
        else {
            echo "<h1>Authentication Failed</h1>";
        }

For some reason, i get Notice: Undefined offset: 1 in and Notice: Undefined offset: 2 in Notices. I don't just want to mute it, i want to fix the notice.

Please help.

Fixed.

     for ($ii=0; $ii<count($ldap_results[0]["sponsorid"][0]); $ii++) {

固定。

     for ($ii=0; $ii<count($ldap_results[0]["sponsorid"][0]); $ii++) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM