Page 1 of 1

ldap question

Posted: Fri Oct 13, 2006 10:22 am
by kingconnections
The script looks up a group then all the members. The members are displayed as dn. I want to resolve the dn and get the names. I already have a function that works based upon thier user name. But the problem is I can't get it to go based upon passing in thier dn.


Here is my code:

Code: Select all

/////////////////////////////////////////////////////////////
//pass in a DN return Full Name
/////////////////////////////////////////////////////////////
function getname_fromdn($dn){
	$first="";
	$last="";
	$full="1";
	//echo"$l_number";
// using ldap bind
$ldaprdn  = 'user';    // ldap rdn or dn
$ldappass = 'password';  // associated password
// connect to ldap server
$ldapconn = ldap_connect("ldapserver.corp.blah.com")
   or die("Could not connect to LDAP server.");
if ($ldapconn) {
   // binding to ldap server
   $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);}
// verify binding
if ($ldapbind) 
       {
       //	print "Congratulations! $ldaprdn is authenticated.<br><br>";
       	}
   else 
       {
      // 	print "Nice try, kid. Better luck next time!";
       	}
$result = ldap_search($ldapconn,"OU=People,dc=corp, dc=blah, dc=com","distinguishedname=$dn") or die ("Error in search query");
if (!$result){
	echo" There is a problem";}
 $info = ldap_get_entries($ldapconn, $result);
// iterate over array and print data for each entry
for ($i=0; $i<$info["count"]; $i++)
{
$first=$info[$i]['givenname'][0];
$last=$info[$i]["sn"][0];
$full=$first." ".$last;
}
if ($full=="1")
{
	$full="$l_number";}
ldap_close($ldapconn);
 return $full;
}
The error: Warning: ldap_search() [function.ldap-search]: Search: Bad search filter in d:\wwwroot\functionlib.php on line 213
Error in search query