You are here

public static function SimpleLdap::ldap_connect in Simple LDAP 7

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

Wrapper function for ldap_connect().

@throw SimpleLdapException

Parameters

string $hostname: If you are using OpenLDAP 2.x.x you can specify a URL instead of the hostname. To use LDAP with SSL, compile OpenLDAP 2.x.x with SSL support, configure PHP with SSL, and set this parameter as ldaps://hostname/

int $port: The port to connect to. Not used when using URLs.

Return value

resource LDAP link identifier

1 call to SimpleLdap::ldap_connect()
SimpleLdapServer::connect in ./SimpleLdapServer.class.php
Connect to the LDAP server.

File

./SimpleLdap.class.php, line 461
Class defining base Simple LDAP functionallity.

Class

SimpleLdap
Simple LDAP class.

Code

public static function ldap_connect($hostname = NULL, $port = 389) {

  // Devel debugging.
  if (variable_get('simple_ldap_devel', FALSE)) {
    dpm(__FUNCTION__);
    dpm(array(
      '$hostname' => $hostname,
      '$port' => $port,
    ));
  }

  // Wrapped function call.
  $return = @ldap_connect($hostname, $port);

  // Debugging.
  if (variable_get('simple_ldap_debug', FALSE)) {
    $message = __FUNCTION__ . '($hostname = @hostname, $port = @port) returns @return';
    $variables = array(
      '@hostname' => print_r($hostname, TRUE),
      '@port' => print_r($port, TRUE),
      '@return' => print_r($return, TRUE),
    );
    watchdog('simple_ldap', $message, $variables, WATCHDOG_DEBUG);
  }

  // Error handling.
  if ($return == FALSE) {
    throw new SimpleLdapException($link_identifier);
  }
  return $return;
}