简体   繁体   中英

php ldap search find attribute

I have a php application which is querying an LDAP server. Using the LDAP Browser desktop application I can see users listed as: cn=joebloe,ou=users,ou=people,o=cuid

with attributes like: 'departmentNumber', 'loginDisabled' etc.

Inside my php application, I have this code:

$sr = ldap_search($ds, "o=$o", "cn=joebloe,ou=users,ou=people,o=cuid"); 

but that code me wrong and just returns a resource link; it would be nice if I can get the value of the attribute of 'loginDisabled'.

How can I do that? Thanks!

Take a look to http://es2.php.net/manual/en/function.ldap-search.php and http://es2.php.net/manual/es/function.ldap-get-entries.php

<?php
// $ds is a valid link identifier for a directory server

// $person is all or part of a person's name, eg "Jo"

$dn = "o=My Company, c=US";
$filter="(|(sn=$person*)(givenname=$person*))";
$justthese = array("ou", "sn", "givenname", "mail");

$sr=ldap_search($ds, $dn, $filter, $justthese);

$info = ldap_get_entries($ds, $sr);

echo $info["count"]." entries returned\n";
?>

Snippet copied from PHP Manual

If you are wanting to get the information on joebloe , then you should be searching for him. I think your base DN string is a little too specific.

Try this out:

$search = ldap_search($ds, "ou=users,ou=people,o=cuid", "cn=joeblow"); 
$results = ldap_get_entries($ds, $search);
var_dump($results);

// Print Department Number
echo "Department Number = ".$results[0]['departmentNumber'][0];

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