Page 1 of 1

ldap_get_entries what?!?

Posted: Fri Jun 05, 2009 2:36 pm
by mmX

Code: Select all

<?php
    session_start();
    
    $invalidEntry = "";
    $invalidInfo = "";
    
    if ($_POST['process'] == 1) {
 
        $pattern = '/^[a-z\d_]{4,28}$/i';
        $username = $_POST['username'];
        $password = $_POST['password'];
 
        // save to session and redirect dis outa 'ere if we coo'
        if (preg_match($pattern, $_POST['username']) > 0) {
            // compare to LDAP - check if user/pass is correct
            
            if (@ldap_connect("serverIP")) {    // ensure this is a valid LDAP server
                $ds = ldap_connect("serverIP");
                if (@ldap_bind($ds,'domainPrefix\\' . $username,$password)){
                    
                    // search memberOf attribute for pertinent groups for the site
                    // array("") contains the search filter(s)
                    $sr=ldap_search($ds, "DC=DC,DC=DC,DC=edu", "samaccountname=$username", array("memberOf", "dn", "description"));  
                    $info = ldap_get_entries($ds, $sr);
                    
                    $entry = ldap_first_entry($ds, $sr);
                    $attrs = ldap_get_attributes($ds, $entry);
                    
                    $manageFunctions = array();
                    $testing = array();
                    for ($i=0; $i < $info["count"]; $i++) {
                        array_push($testing, $info[$i]["dn"]);
                        array_push($testing, $info[$i]["description"]);
                        array_push($manageFunctions, $info[$i]["memberOf"]);
                    }
                    
                    ldap_close($ds);
                    
                    $_SESSION['testing'] = $testing[0];
                    $_SESSION['ID'] = $testing[1];
                    $_SESSION['testing2'] = $iterateValue;
                    
                    $_SESSION['loggedIn'] = "Yes";
                    $_SESSION['samaccountname'] = $username;
                    $_SESSION['manageFunctions'] = $manageFunctions;
                    header("location: home.php");
                    exit();
                }else{
                    $invalidInfo = "Sorry, your username/password is incorrect";
                }
            }else{
                $invalidInfo = "The page cannot contact the authentication server.  Please contact an administrator";}
        }else{
            $invalidEntry = "Please enter a valid username.";}
    }
?>
Lines 32 and 33 work; but, line 34 doesn't... what gives?

Re: ldap_get_entries what?!?

Posted: Fri Jun 05, 2009 3:27 pm
by pickle
dump out $info - is it in the format you expect?

Re: ldap_get_entries what?!?

Posted: Fri Jun 05, 2009 3:45 pm
by mmX
Yeah, I believe this is correct:

Code: Select all

Array ( [count] => 1 [0] => Array ( [description] => Array ( [count] => 1 [0] => 8******* ) [0] => description [memberof] => Array ( [count] => 4 [0] => CN=Department Supervisor,OU=GULA Net,OU=Department Groups,DC=DC,DC=DC,DC=EDU [1] => CN=TerminalServices,OU=Department Groups,DC=DC,DC=DC,DC=EDU [2] => CN=Group(Local),OU=OU,OU=Staff,DC=DC,DC=DC,DC=EDU [3] => CN=users,OU=Department Groups,DC=DC,DC=DC,DC=EDU ) [1] => memberof [count] => 2 [dn] => CN=TEST\,USER1,OU=Test User,OU=Staff,DC=DC,DC=DC,DC=EDU ) )
Changed some values that probably don't need to be known.
But, [memberof] => Array (... is what I'm trying to pull with line 34, yeah?
Line 34:

Code: Select all

array_push($manageFunctions, $info[$i]["memberOf"]);

Re: ldap_get_entries what?!?

Posted: Mon Jun 08, 2009 4:34 pm
by pickle
Dump out $info[$i]['member'] like this:

Code: Select all

<?php echo '<pre>';
print_r($info[$i]['member']);
echo '</pre>';
It'll be much more legible

Do the same for $manageFunctions after the for loop.