ldap_get_entries what?!?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mmX
Forum Newbie
Posts: 10
Joined: Fri Apr 03, 2009 2:13 pm

ldap_get_entries what?!?

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: ldap_get_entries what?!?

Post by pickle »

dump out $info - is it in the format you expect?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
mmX
Forum Newbie
Posts: 10
Joined: Fri Apr 03, 2009 2:13 pm

Re: ldap_get_entries what?!?

Post 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"]);
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: ldap_get_entries what?!?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply