hi Chris,
Comments below...
Regards,
Rob.
On Sat, 2003-12-20 at 19:07, Chris Shaffer wrote:
> Hey Robert:
>
> Cool... I'm looking for a way to retrieve Last Name, First Name, and
> (now that you mention it) Phone number from LDAP. Here's the
> function I was hoping to base this all off of:
> function ldap_email_from_username( $p_username ) {
> $t_ldap_organization = config_get(
> 'ldap_organization' );
> $t_ldap_root_dn = config_get(
> 'ldap_root_dn' );
>
> $t_search_filter =
> "(&$t_ldap_organization(uid=$p_username))";
> $t_search_attrs = array( 'uid', 'mail', 'dn' );
> $t_ds = ldap_connect_bind();
>
> $t_sr = ldap_search( $t_ds, $t_ldap_root_dn,
> $t_search_filter, $t_search_attrs );
> $t_info = ldap_get_entries( $t_ds, $t_sr );
> ldap_free_result( $t_sr );
> ldap_unbind( $t_ds );
>
> return $t_info[0]['mail'][0];
> }
> I would guess that you could just change the fifth line to be
> '$t_search_attrs = array( 'uid', 'sn', 'dn' );' for a Last Name
> search. And the last line would be come 'return $t_info[0]['sn'][0];'
> to return the value. Does that seem right?
>
The array $t_search_attrs contains the attributes you want to return
from the search.
So you could set it up as follows:
$t_search_attrs = array( 'mail', 'sn', 'cn', 'givenName', 'initials',
'telephoneNumber' );
cn = Common Name
Then you need to retrieve the values for each attribute.
try doing a var_dump() on the returned search results ( $t_info ).
It would be worth your time lookin up the ldap_search function:
http://au2.php.net/manual/en/function.ldap-search.php
Let me know if there's anything else I can help with.
I'll be patching the above function and sending the patch
into the list, as I've noticed the list of attributes being searched
for is not optimal for this case.
|