Jump to content

Archived

This topic is now archived and is closed to further replies.

countnikon

Help creating an LDAP class

Recommended Posts

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?

[code]
<?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;
?>
[/code]
I know the ldap searches are working because it is not erroring out anymore.  Any help would be appreciated.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.