当前位置: 首页>>代码示例>>PHP>>正文


PHP ldap_connect函数代码示例

本文整理汇总了PHP中ldap_connect函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_connect函数的具体用法?PHP ldap_connect怎么用?PHP ldap_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ldap_connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: lookup

 public static function lookup($query, $type)
 {
     $person_array = array();
     $x500 = ldap_connect('ldap.utexas.edu');
     $bind = ldap_bind($x500);
     $dn = "ou=people,dc=directory,dc=utexas,dc=edu";
     $filter = "{$type}={$query}";
     $ldap_result = @ldap_search($x500, $dn, $filter);
     $attributes = array('eid' => 'uid', 'email' => 'mail', 'name' => 'cn', 'firstname' => 'givenname', 'lastname' => 'sn', 'office' => 'utexasedupersonofficelocation', 'phone' => 'telephonenumber', 'title' => 'title', 'unit' => 'ou');
     if ($ldap_result) {
         $entry_array = ldap_get_entries($x500, $ldap_result);
         for ($i = 0; $i < count($entry_array) - 1; $i++) {
             $person = array();
             if ($entry_array[$i]) {
                 $eid = $entry_array[$i]['uid'][0];
                 foreach ($attributes as $label => $att) {
                     if (isset($entry_array[$i][$att])) {
                         $person[$label] = $entry_array[$i][$att][0];
                     } else {
                         $person[$label] = '';
                     }
                 }
             }
             $person_array[] = $person;
         }
         ldap_close($x500);
     }
     return $person_array;
 }
开发者ID:pkeane,项目名称:humptydumpty,代码行数:29,代码来源:Utlookup.php

示例2: connect

 /**
  * method to connect to the ldap server
  */
 public function connect()
 {
     $this->connection = ldap_connect($this->LDAPServer);
     ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3);
     ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0);
     $ldap_bind = ldap_bind($this->connection, $this->LDAPDomain . "\\" . $this->LDAPUser, $this->LDAPPassword);
 }
开发者ID:bayugyug,项目名称:LDAP-Api,代码行数:10,代码来源:class.PHPLdap.php

示例3: open

 protected function open()
 {
     $bind = \ldap_connect($this->ldap_server);
     \ldap_set_option($this->bind, LDAP_OPT_PROTOCOL_VERSION, 3);
     \ldap_bind($bind, $this->admin_user . ',' . $this->base_dn, $this->admin_password);
     $this->bind = $bind;
 }
开发者ID:guillaum3f,项目名称:codie,代码行数:7,代码来源:ldap.class.php

示例4: BackendSearchLDAP

 /**
  * Initializes the backend to perform the search
  * Connects to the LDAP server using the values from the configuration
  *
  *
  * @access public
  * @return
  * @throws StatusException
  */
 public function BackendSearchLDAP()
 {
     if (!function_exists("ldap_connect")) {
         throw new StatusException("BackendSearchLDAP(): php-ldap is not installed. Search aborted.", SYNC_SEARCHSTATUS_STORE_SERVERERROR, null, LOGLEVEL_FATAL);
     }
     // connect to LDAP
     $this->connection = @ldap_connect(LDAP_HOST, LDAP_PORT);
     @ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3);
     // Authenticate
     if (constant('ANONYMOUS_BIND') === true) {
         if (!@ldap_bind($this->connection)) {
             $this->connection = false;
             throw new StatusException("BackendSearchLDAP(): Could not bind anonymously to server! Search aborted.", SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED, null, LOGLEVEL_ERROR);
         }
     } else {
         if (constant('LDAP_BIND_USER') != "") {
             if (!@ldap_bind($this->connection, LDAP_BIND_USER, LDAP_BIND_PASSWORD)) {
                 $this->connection = false;
                 throw new StatusException(sprintf("BackendSearchLDAP(): Could not bind to server with user '%s' and specified password! Search aborted.", LDAP_BIND_USER), SYNC_SEARCHSTATUS_STORE_ACCESSDENIED, null, LOGLEVEL_ERROR);
             }
         } else {
             // it would be possible to use the users login and password to authenticate on the LDAP server
             // the main $backend has to keep these values so they could be used here
             $this->connection = false;
             throw new StatusException("BackendSearchLDAP(): neither anonymous nor default bind enabled. Other options not implemented.", SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED, null, LOGLEVEL_ERROR);
         }
     }
 }
开发者ID:alanturing1,项目名称:Z-Push-contrib,代码行数:37,代码来源:searchldap.php

示例5: login_ad

function login_ad($user_, $pass_, $tipo_)
{
    //Comienzo la conexión al servidor para tomar los datos de active directory
    $host = get_config('host');
    $puerto = get_config('puerto');
    $filter = "sAMAccountName=" . $user_ . "*";
    $attr = array("displayname", "mail", "givenname", "sn", "useraccountcontrol");
    $dn = get_config('dn');
    $conex = ldap_connect($host, $puerto) or die("No ha sido posible conectarse al servidor");
    if (!ldap_set_option($conex, LDAP_OPT_PROTOCOL_VERSION, 3)) {
        echo "<br>Failed to set protocol version to 3";
    }
    if ($conex) {
        $dominio = get_config("dominio");
        $r = @ldap_bind($conex, $user_ . $dominio, $pass_);
        $existe = get_perfil($user_, $tipo_);
        if ($r && count($existe) > 0) {
            //LOGIN CORRECTO
            $result = ldap_search($conex, $dn, $filter, $attr);
            $entries = ldap_get_entries($conex, $result);
            for ($i = 0; $i < $entries["count"]; $i++) {
                $nombre = fix_data(utf8_decode($entries[$i]["givenname"][0]));
                $apellidos = fix_data(utf8_decode($entries[$i]["sn"][0]));
                $email = fix_data($entries[$i]["mail"][0]);
                //Acutalizar información desde AD en la tabla de empleados
                $s_ = "update empleados set nombre='{$nombre}', apellidos='{$apellidos}', mail='{$email}' where id='{$existe['id']}'";
                $r_ = mysql_query($s_);
                session_name("loginUsuario");
                session_start();
                $_SESSION['NAME'] = $nombre . " " . $apellidos;
                $_SESSION['USER'] = $user_;
                $_SESSION['IDEMP'] = $existe['id'];
                $_SESSION['AUSENCIA'] = get_ausencia($existe['id']);
                $_SESSION['DEPTO'] = $existe['depto'];
                $_SESSION['TYPE'] = $tipo_;
            }
            switch ($tipo_) {
                case "administrador":
                    header("Location: admin/inicio.php");
                    break;
                case "capturista":
                    header("Location: capturista/inicio.php");
                    break;
                case "autorizador":
                    header("Location: autorizador/scrap_firmar.php");
                    break;
                case "reportes":
                    header("Location: reportes/rep_general.php?op=listado");
                    break;
            }
        } else {
            echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=index.php?error=2&user_={$user_}&tipo_={$tipo_}\">";
            exit;
        }
        ldap_close($conex);
    } else {
        echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=index.php?error=3&user_={$user_}&tipo_={$tipo_}\">";
        exit;
    }
}
开发者ID:BrutalAndSick,项目名称:scrap,代码行数:60,代码来源:index11111.php

示例6: __construct

 public function __construct($userKey)
 {
     $config = new Configuration();
     //try to connect to ldap if the settings are entered
     if ($config->ldap->host) {
         //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/.
         //note that connect happens regardless if host is valid
         $ds = ldap_connect($config->ldap->host);
         //may need ldap_bind( $ds, $username, $password )
         $bd = ldap_bind($ds) or die("<br /><h3>" . _("Could not connect to ") . $config->ldap->host . "</h3>");
         if ($bd) {
             $filter = $config->ldap->search_key . "=" . $userKey;
             $sr = ldap_search($ds, $config->ldap->base_dn, $filter);
             if ($entries = ldap_get_entries($ds, $sr)) {
                 $entry = $entries[0];
                 $fieldNames = array('fname', 'lname', 'email', 'phone', 'department', 'title', 'address');
                 foreach ($fieldNames as $fieldName) {
                     $configName = $fieldName . '_field';
                     $this->{$fieldName} = $entry[$config->ldap->{$configName}][0];
                 }
                 $this->fullname = addslashes($this->fname . ' ' . $this->lname);
             }
             ldap_close($ds);
         }
     }
 }
开发者ID:billdueber,项目名称:resources,代码行数:26,代码来源:LdapPerson.php

示例7: install_etape_ldap4_dist

function install_etape_ldap4_dist()
{
    $adresse_ldap = _request('adresse_ldap');
    $login_ldap = _request('login_ldap');
    $pass_ldap = _request('pass_ldap');
    $port_ldap = _request('port_ldap');
    $base_ldap = _request('base_ldap');
    $base_ldap_text = _request('base_ldap_text');
    if (!$base_ldap) {
        $base_ldap = $base_ldap_text;
    }
    echo install_debut_html();
    $ldap_link = ldap_connect($adresse_ldap, $port_ldap);
    @ldap_bind($ldap_link, $login_ldap, $pass_ldap);
    // Essayer de verifier le chemin fourni
    $r = @ldap_compare($ldap_link, $base_ldap, "objectClass", "");
    $fail = ldap_errno($ldap_link) == 32;
    if ($fail) {
        echo info_etape(_T('info_chemin_acces_annuaire')), info_progression_etape(3, 'etape_ldap', 'install/', true), "<div class='error'><p><b>" . _T('avis_operation_echec') . "</b></p><p>" . _T('avis_chemin_invalide_1'), " (<tt>" . htmlspecialchars($base_ldap) . "</tt>) " . _T('avis_chemin_invalide_2') . "</p></div>";
    } else {
        info_etape(_T('info_reglage_ldap'));
        echo info_progression_etape(4, 'etape_ldap', 'install/');
        $statuts = liste_statuts_ldap();
        $statut_ldap = defined('_INSTALL_STATUT_LDAP') ? _INSTALL_STATUT_LDAP : $GLOBALS['liste_des_statuts']['info_redacteurs'];
        $res = install_propager(array('adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap')) . "<input type='hidden' name='etape' value='ldap5' />" . "<input type='hidden' name='base_ldap' value='" . htmlentities($base_ldap) . "' />" . fieldset(_T('info_statut_utilisateurs_1'), array('statut_ldap' => array('label' => _T('info_statut_utilisateurs_2') . '<br />', 'valeur' => $statut_ldap, 'alternatives' => $statuts))) . install_ldap_correspondances() . bouton_suivant();
        echo generer_form_ecrire('install', $res);
    }
    echo install_fin_html();
}
开发者ID:nursit,项目名称:SPIP,代码行数:29,代码来源:etape_ldap4.php

示例8: DoTest

 function DoTest($testname, $param, $hostname, $timeout, $params)
 {
     global $NATS;
     $url = $params[0];
     $bind = $params[1];
     $pasw = $params[2];
     $base = $params[3];
     $filter = $params[4];
     $ds = ldap_connect($url);
     if (!$ds) {
         return -2;
     }
     $ldap = $bind && $pasw ? ldap_bind($ds, $bind, $pasw) : ldap_bind($ds);
     if (!$ldap) {
         return -1;
     }
     if ($base && $filter) {
         $search = ldap_search($ds, $base, $filter);
         $val = ldap_count_entries($ds, $search);
     } else {
         $val = 1;
     }
     ldap_close($ds);
     return $val;
 }
开发者ID:alvunera,项目名称:FreeNats-PlugIn,代码行数:25,代码来源:ldap.inc.php

示例9: connect

 protected function connect($ldap_host, $ldap_port)
 {
     if ($ldap_host && $ldap_port) {
         return @ldap_connect($ldap_host, $ldap_port);
     }
     return false;
 }
开发者ID:vionox,项目名称:sentinel-ldap,代码行数:7,代码来源:Manager.php

示例10: search_uidspip

function search_uidspip ($filter,$ldap_server, $ldap_port, $dn) {
  global  $ldap_grp_attr;
  
  // LDAP attributs
  $ldap_grp_attr = array (
    "cn",
    "memberuid"  );

  $ds = @ldap_connect ( $ldap_server, $ldap_port );
  if ( $ds ) {
    $r = @ldap_bind ( $ds ); // Bind anonyme
    if ($r) {
      $result=@ldap_list ($ds, $dn["groups"], $filter, $ldap_grp_attr);
      if ($result) {
        $info = ldap_get_entries( $ds, $result );
        if ($info["count"]) {
          // Stockage des logins des membres des classes
          //  dans le tableau $ret
          $init=0;
          for ($loop=0; $loop < $info["count"]; $loop++) {
            $group=split ("[\_\]",$info[$loop]["cn"][0],2);
            for ( $i = 0; $i < $info[$loop]["memberuid"]["count"]; $i++ ) {
              $ret[$init]["uid"] = $info[$loop]["memberuid"][$i];
              $ret[$init]["cat"] = $group[0];
              $init++;
            }
          }
        }
        ldap_free_result ( $result );
      }
    } 
    @ldap_close ( $ds );
  } 
  return $ret;
}
开发者ID:rhertzog,项目名称:lcs,代码行数:35,代码来源:accorder_comptes_lcs.php

示例11: connectToLdap

 /**
  * Makes a connection to LDAP using the settings in Admin > Settings.
  *
  * @author [A. Gianotto] [<snipe@snipe.net>]
  * @since [v3.0]
  * @return connection
  */
 public static function connectToLdap()
 {
     $ldap_host = Setting::getSettings()->ldap_server;
     $ldap_version = Setting::getSettings()->ldap_version;
     $ldap_server_cert_ignore = Setting::getSettings()->ldap_server_cert_ignore;
     $ldap_use_tls = Setting::getSettings()->ldap_tls;
     // If we are ignoring the SSL cert we need to setup the environment variable
     // before we create the connection
     if ($ldap_server_cert_ignore == '1') {
         putenv('LDAPTLS_REQCERT=never');
     }
     // If the user specifies where CA Certs are, make sure to use them
     if (env("LDAPTLS_CACERT")) {
         putenv("LDAPTLS_CACERT=" . env("LDAPTLS_CACERT"));
     }
     $connection = @ldap_connect($ldap_host);
     if (!$connection) {
         throw new Exception('Could not connect to LDAP server at ' . $ldap_host . '. Please check your LDAP server name and port number in your settings.');
     }
     // Needed for AD
     ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
     ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, $ldap_version);
     if ($ldap_use_tls == '1') {
         ldap_start_tls($connection);
     }
     return $connection;
 }
开发者ID:jbirdkerr,项目名称:snipe-it,代码行数:34,代码来源:Ldap.php

示例12: _init

 /**
  * ->_init()
  * connect and bind to the LDAP host
  */
 function _init()
 {
     if ($this->_ldap = ldap_connect(LDAP_AUTH_HOST)) {
         // must be a valid LDAP server!
         global $LDAP_SET_OPTION;
         if (!empty($LDAP_SET_OPTION)) {
             foreach ($LDAP_SET_OPTION as $key => $value) {
                 //if (is_string($key) and defined($key))
                 //    $key = constant($key);
                 ldap_set_option($this->_ldap, $key, $value);
             }
         }
         if (LDAP_AUTH_USER) {
             if (LDAP_AUTH_PASSWORD) {
                 // Windows Active Directory Server is strict
                 $r = ldap_bind($this->_ldap, LDAP_AUTH_USER, LDAP_AUTH_PASSWORD);
             } else {
                 $r = ldap_bind($this->_ldap, LDAP_AUTH_USER);
             }
         } else {
             $r = true;
         }
         // anonymous bind allowed
         if (!$r) {
             $this->_free();
             trigger_error(sprintf(_("Unable to bind LDAP server %s using %s %s"), LDAP_AUTH_HOST, LDAP_AUTH_USER, LDAP_AUTH_PASSWORD), E_USER_WARNING);
             return false;
         }
         return $this->_ldap;
     } else {
         return false;
     }
 }
开发者ID:hugcoday,项目名称:wiki,代码行数:37,代码来源:LDAP.php

示例13: lookupUser

 public function lookupUser($credentials)
 {
     $username = $credentials['username'];
     $password = $credentials['password'];
     $this->log('Ldap: looking up user "' . $username . '" in LDAP server ');
     $sourceConfig = $this->source;
     $server = parse_url($sourceConfig['url']);
     if (empty($server['host'])) {
         return false;
         // oops
     }
     $connect = ldap_connect($server['host'], empty($server['port']) ? 389 : $server['port']);
     ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
     ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
     //$connect=ldap_connect($server['host']);
     $this->log('Connected');
     if (!$connect) {
         throw new PHPDS_exception('Unable to connect to the LDAP server');
     }
     if ($sourceConfig['namePattern']) {
         $username = PU_sprintfn($sourceConfig['namePattern'], array($username));
     }
     if (!@ldap_bind($connect, $username, $password)) {
         return false;
         // if we can't bind it's likely the user is unknown or the password is wrong
     }
     $this->log('Bound');
     return true;
 }
开发者ID:tejdeeps,项目名称:tejcs.com,代码行数:29,代码来源:AUTH_ldap.class.php

示例14: ldap_init

function ldap_init()
{
    global $ds, $config;
    if (!is_resource($ds)) {
        print_debug("LDAP[Connecting to " . implode(",", $config['auth_ldap_server']) . "]");
        $ds = @ldap_connect(implode(",", $config['auth_ldap_server']), $config['auth_ldap_port']);
        print_debug("LDAP[Connected]");
        if ($config['auth_ldap_starttls'] && ($config['auth_ldap_starttls'] == 'optional' || $config['auth_ldap_starttls'] == 'require')) {
            $tls = ldap_start_tls($ds);
            if ($config['auth_ldap_starttls'] == 'require' && $tls == FALSE) {
                session_logout();
                print_error("Fatal error: LDAP TLS required but not successfully negotiated [" . ldap_error($ds) . "]");
                exit;
            }
        }
        if ($config['auth_ldap_referrals']) {
            ldap_set_option($ds, LDAP_OPT_REFERRALS, $config['auth_ldap_referrals']);
            print_debug("LDAP[Referrals][Set to " . $config['auth_ldap_referrals'] . "]");
        } else {
            ldap_set_option($ds, LDAP_OPT_REFERRALS, FALSE);
            print_debug("LDAP[Referrals][Disabled]");
        }
        if ($config['auth_ldap_version']) {
            ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $config['auth_ldap_version']);
            print_debug("LDAP[Version][Set to " . $config['auth_ldap_version'] . "]");
        }
    }
}
开发者ID:skive,项目名称:observium,代码行数:28,代码来源:ldap.inc.php

示例15: get_ldap_members

function get_ldap_members($group, $user, $password)
{
    global $ldap_host;
    global $ldap_dn;
    $LDAPFieldsToFind = array("member");
    print "{$ldap_host} {$ldap_dn}\n";
    $ldap = ldap_connect($ldap_host) or die("Could not connect to LDAP");
    // OPTIONS TO AD
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
    ldap_bind($ldap, $user, $password) or die("Could not bind to LDAP");
    //check if group is just a name or an ldap string
    $group_cn = preg_match("/cn=/i", $group) ? $group : "cn={$group}";
    $results = ldap_search($ldap, $ldap_dn, $group_cn, $LDAPFieldsToFind);
    $member_list = ldap_get_entries($ldap, $results);
    $group_member_details = array();
    if (is_array($member_list[0])) {
        foreach ($member_list[0] as $list) {
            if (is_array($list)) {
                foreach ($list as $member) {
                    $member_dn = explode_dn($member);
                    $member_cn = str_replace("CN=", "", $member_dn[0]);
                    $member_search = ldap_search($ldap, $ldap_dn, "(CN=" . $member_cn . ")");
                    $member_details = ldap_get_entries($ldap, $member_search);
                    $group_member_details[] = array($member_details[0]['samaccountname'][0], $member_details[0]['displayname'][0], $member_details[0]['useraccountcontrol'][0]);
                }
            }
        }
    }
    ldap_close($ldap);
    array_shift($group_member_details);
    return $group_member_details;
    ldap_unbind($ldap);
}
开发者ID:LFCavalcanti,项目名称:pfsense-packages,代码行数:34,代码来源:dansguardian_ldap.php


注:本文中的ldap_connect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。