Previously, Miguel Carvalho said:
> if a do
>     ldapsearch -o ",o=xyz" "ent=entry1,uid=ldap,ou=People,o=xyz", it
> works just fine.
> 
> How can i access the entry  "ent=entry1,uid=ldap,ou=People,o=xyz" using
> ldap_search/ldap_list or ldap_read?
> 
> I have tried ldap_search... but i can not find how to write the filter.

    $host = 'localhost';

    $bindcred = 'uid=admin';    // adjust for your system
    $bindpass = 'somepasswd';   // adjust for your system

    $base = 'o=xyz';                            // where to start in tree

    //$base = 'uid=ldap,ou=People,o=xyz';       // more specific... and
                                                // probably faster too

    $filter = 'ent=entry1';             // what to search on

    $conn = ldap_connect($host);
    if (! $conn)
        die('LDAP connection failed!');

    $result = ldap_bind($conn, $bindcred, $bindpass);
    if (! $result)
        die('LDAP BIND failed!');

    $result = ldap_search($conn, $base, $filter);
    if (! $result)
        die('LDAP SRCH failed!');

    $numentries = ldap_count_entries($conn, $result);
    print 'Found ' . $numentries . 'matches<br>';

    if ($numentries > 0)
        $info = ldap_get_entries($conn, $result);

    for ($i = 0; $i < $info['count']; $i++) {
        print $info[$i]['uid'][0];
    }

    // $info is a multidimensional array with your result set.
    // you can use another attribute name in place of 'uid'...
    // for multivalued attributes (such as 'objectclass') you can use
    // numbers higher than 0 in the last set of brackets to see the
    // other values... i.e.
    //
    // $info[$i]['objectclass'][0];
    // $info[$i]['objectclass'][1];
    // $info[$i]['objectclass'][2];
    //
    // .. etc

-- 
Why don't sheep shrink when it rains?  -George Carlin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to