You are here

public function SimpleLdapServer::bind in Simple LDAP 7

Same name and namespace in other branches
  1. 7.2 SimpleLdapServer.class.php \SimpleLdapServer::bind()

Connect and bind to the LDAP server.

Parameters

mixed $binddn: Use the given DN while binding. Use NULL for an anonymous bind.

mixed $bindpw: Use the given password while binding. Use NULL for an anonymous bind.

boolean $rebind: Reset the object's bind credentials to those provided. Otherwise, just bind to verify that the credentials are valid.

Return value

boolean TRUE on success, FALSE on failure.

7 calls to SimpleLdapServer::bind()
SimpleLdapServer::add in ./SimpleLdapServer.class.php
Add an entry to the LDAP directory.
SimpleLdapServer::compare in ./SimpleLdapServer.class.php
Compare the given attribute value with what is in the LDAP server.
SimpleLdapServer::delete in ./SimpleLdapServer.class.php
Delete an entry from the directory.
SimpleLdapServer::modify in ./SimpleLdapServer.class.php
Modify an LDAP entry.
SimpleLdapServer::move in ./SimpleLdapServer.class.php
Move an entry to a new DN.

... See full list

File

./SimpleLdapServer.class.php, line 248
Class to handle LDAP server connections and related operations.

Class

SimpleLdapServer
Simple LDAP server class.

Code

public function bind($binddn = FALSE, $bindpw = FALSE, $rebind = FALSE) {

  // Connect first.
  try {
    $this
      ->connect();
  } catch (SimpleLdapException $e) {
    return FALSE;
  }

  // Reset bind DN if provided, and reset is specified.
  if ($rebind && $binddn !== FALSE && $binddn != $this->binddn) {
    $this->binddn = $binddn;
    $this->bound = FALSE;
  }

  // Reset bind PW if provided, and reset is specified.
  if ($rebind && $bindpw !== FALSE && $bindpw != $this->bindpw) {
    $this->bindpw = $bindpw;
    $this->bound = FALSE;
  }

  // Attempt to bind if not already bound, or rebind is specified, or
  // credentials are given.
  if (!$this->bound || $rebind || $binddn !== FALSE && $bindpw !== FALSE) {

    // Bind to the LDAP server.
    if ($rebind || $binddn === FALSE || $bindpw === FALSE) {
      $this->bound = SimpleLdap::ldap_bind($this->resource, $this->binddn, $this->bindpw);
    }
    else {

      // Bind with the given credentials. This is a temporary bind to verify
      // the password, so $this->bound is reset to FALSE.
      $result = SimpleLdap::ldap_bind($this->resource, $binddn, $bindpw);
      $this->bound = FALSE;
      return $result;
    }

    // If paged queries are enabled, verify whether the server supports them.
    if ($this->bound && $this->pagesize) {

      // Load the rootDSE.
      $this
        ->rootdse();

      // Look for the paged query OID supported control.
      if (!in_array('1.2.840.113556.1.4.319', $this->rootdse['supportedcontrol'])) {
        $this->pagesize = FALSE;
      }
    }
  }
  return $this->bound;
}