예제 #1
0
 /**
  *
  * @throws LdapException
  */
 public function connect()
 {
     if (!extension_loaded('ldap')) {
         throw new LdapException('The ldap module is needed.');
     }
     $this->resource = @ldap_connect($this->host, $this->port);
     if ($this->resource === false) {
         $this->close();
         ErrorHandler::throwException($this);
     }
     ldap_set_option($this->resource, LDAP_OPT_REFERRALS, 0);
     ldap_set_option($this->resource, LDAP_OPT_PROTOCOL_VERSION, $this->protocolVersion);
     if ($this->useTls) {
         ldap_start_tls($this->resource);
     }
     $bind = @ldap_bind($this->resource, $this->user, $this->pass);
     if ($bind === false) {
         try {
             // using resource before close connection (prevent null)
             ErrorHandler::throwException($this);
         } catch (Exception $ex) {
             $this->close();
             throw $ex;
         }
     }
     $this->connected = true;
 }
예제 #2
0
 /**
  *
  * @param string $dn
  * @throws LdapException
  */
 public function delete($dn)
 {
     $this->checkConnection();
     $resource = $this->conn->getResource();
     $rs = @ldap_delete($resource, $dn);
     if ($rs === false) {
         ErrorHandler::throwException($this->conn);
     }
 }