PHP - ldap_search() filter. How to search for user

Posted by cvack on Stack Overflow See other posts from Stack Overflow or by cvack
Published on 2010-05-28T07:25:06Z Indexed on 2010/05/28 7:32 UTC
Read the original article Hit count: 331

Filed under:
|
|
|

$_SERVER['REMOTE_USER'] returns the username of the user logged in to an Active Directory. I want to retrive this users info by using ldap_search().

This is what I have now:

$ad = // ldap_connection id
$filter = "(|(sn=$username*)(givenname=$username*))";
$attr = array("displayname", "mail", "mobile", "homephone", "telephonenumber", "streetaddress", "postalcode", "physicaldeliveryofficename", "l");
$dn = // OU, DC etc..

ldap_search($ad,$dn,$filter,$attr);

It works, but i'm not sure it will work if two users have almost the same names. How do I only search for their unique username so that i always only get one user?

© Stack Overflow or respective owner

Related posts about php

Related posts about active-directory