Horde_Ldap::bind PHP Method

bind() public method

This function binds with the given DN and password to the server. In case no connection has been made yet, it will be started and STARTTLS issued if appropiate. The internal bind configuration is not being updated, so if you call bind() without parameters, you can rebind with the credentials provided at first connecting to the server.
public bind ( string $dn = null, string $password = null )
$dn string DN for binding.
$password string Password for binding.
    public function bind($dn = null, $password = null)
    {
        /* Fetch current bind credentials. */
        if (is_null($dn)) {
            $dn = $this->_config['binddn'];
        }
        if (is_null($password)) {
            $password = $this->_config['bindpw'];
        }
        /* Connect first, if we haven't so far.  This will also bind
         * us to the server. */
        if (!$this->_link) {
            /* Store old credentials so we can revert them later, then
             * overwrite config with new bind credentials. */
            $olddn = $this->_config['binddn'];
            $oldpw = $this->_config['bindpw'];
            /* Overwrite bind credentials in config so
             * _connect() knows about them. */
            $this->_config['binddn'] = $dn;
            $this->_config['bindpw'] = $password;
            /* Try to connect with provided credentials. */
            $msg = $this->_connect();
            /* Reset to previous config. */
            $this->_config['binddn'] = $olddn;
            $this->_config['bindpw'] = $oldpw;
            return;
        }
        /* Do the requested bind as we are asked to bind manually. */
        if (empty($dn)) {
            /* Anonymous bind. */
            $msg = @ldap_bind($this->_link);
        } else {
            /* Privileged bind. */
            $msg = @ldap_bind($this->_link, $dn, $password);
        }
        if (!$msg) {
            throw new Horde_Ldap_Exception('Bind failed: ' . @ldap_error($this->_link), @ldap_errno($this->_link));
        }
    }

Usage Example

示例#1
0
文件: Ldap.php 项目: jubinpatel/horde
 /**
  * Rebinds to the LDAP server.
  *
  * @param boolean $write  Whether to rebind for write access. Use false
  *                        after finishing write actions.
  *
  * @throws Horde_Ldap_Exception
  */
 protected function _rebind($write)
 {
     if ($write) {
         $this->_ldap->bind($this->_params['writedn'], $this->_params['writepw']);
     } else {
         $this->_ldap->bind();
     }
 }
All Usage Examples Of Horde_Ldap::bind