Jump to content


Photo

Help creating an LDAP class


  • Please log in to reply
1 reply to this topic

#1 countnikon

countnikon
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 05 July 2006 - 10:03 PM

Hello Everybody,

I'm having trouble with this class I'm making for doing LDAP authentication and Lookups.  However, I cannot output my results.  Can somebody shed some light on this please?

<?PHP
class ldap
{
  var $ldapconn; //ldap connection storage variable
  var $ldap_bind; //ldap bind storage variable
  var $entries;  //ldap entries variable
  var $dc = "my dc server";
  var $port = 389;
  var $ldapLookupUser = "ldaplookupuser";
  var $ldapLookupPass = "ldaplookup pass";
  
  function ldapConn()
  {
    $this->ldapconn = @ldap_connect($dc,$port);
  }
  function ldapBind()
  {
    $this->ldap_bind = @ldap_bind($this->ldapconn,$ldapLookupUser,$ldapLookupPass);
  }
  function ldapAuthenticate()
  {
    if(@ldap_bind($this->ldapconn,$username,$password))
      return true;
    else
      return false;
  }
  function ldapSearch($by,$search,$ou)
  {
    $read = @ldap_search($this->ldapconn, "ou=$ou,dc=mydc,dc=net", "samaccountname=*$search*");
    $entries = @ldap_get_entries($this->ldapconn, $read);
    for ($i=0; $i<$entries["count"]; $i++)
    {
      if($entries[$i][$by][0])
        $values = $values.$entries[$i][$by][0];
    }
    return $values;
  }
}
$ldap = new ldap;
$ldap->ldapConn();
$ldap->ldapBind();
$results = $ldap->ldapSearch("mail","myusrname","myou");
echo $results;
?>
I know the ldap searches are working because it is not erroring out anymore.  Any help would be appreciated.

#2 countnikon

countnikon
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 06 July 2006 - 04:44 PM

Anybody here good with classes?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users