How to get the DN for a given samaccountname:
/*the connecting part*/
$ldap_conn = ldap_connect($hostname, $port);
$bind = ldap_bind($ldap_conn, $username, $password);
/*the connecting part*/
$samaccountname = john.doe;
$filter="(samaccountname=$samaccountname)";
$dn="OU=PEOPLE, DC=example, DC=com"; //even if it seems obvious I note here that the dn is just an example, you'll have to provide an OU and DC of your own
$res = ldap_search($ldap_conn, $dn, $filter);
$first = ldap_first_entry($ldap_conn, $res);
$data = ldap_get_dn($ldap_conn, $first);
echo "The desired DN is: ".$data;ldap_get_dn
(PHP 4, PHP 5, PHP 7, PHP 8)
ldap_get_dn — Get the DN of a result entry
Description
Finds out the DN of an entry in the result.
Parameters
ldap-
An LDAP\Connection instance, returned by ldap_connect().
entry-
An LDAP\ResultEntry instance.
Return Values
Returns the DN of the result entry and false on error.
Changelog
| Version | Description |
|---|---|
| 8.1.0 |
The ldap parameter expects an LDAP\Connection
instance now; previously, a valid ldap link resource was expected.
|
| 8.1.0 |
The entry parameter expects an LDAP\ResultEntry
instance now; previously, a valid ldap result entry resource was expected.
|
+add a note
User Contributed Notes 1 note
radulescuiuliamaria at yahoo dot com ¶
10 years ago