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


PHP ldap_set_option函数代码示例

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


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

示例1: login

 function login($username, $password)
 {
     global $_SESSION;
     // Check for LDAP functions
     if (!function_exists('ldap_connect')) {
         $ex = 'LDAP support is not enabled in your PHP configuration.';
         if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
             ob_start();
             phpinfo(INFO_GENERAL);
             $phpinfo = ob_get_contents();
             ob_end_clean();
             preg_match('/Loaded Configuration File <\\/td><td.*?>(.*?)\\s*</', $phpinfo, $phpinfo);
             $ex .= ' You probably just need to uncomment the line ;extension=php_ldap.dll in php.ini' . (count($phpinfo) > 1 ? ' (' . trim($phpinfo[1]) . ')' : '') . ' by removing the ";" and restart your web server.';
         } else {
             if (strtolower(substr(PHP_OS, 0, 5)) == 'Linux') {
                 $ex .= ' You probably need to install the php5-ldap (or similar depending on your distribution) package.';
             }
         }
         throw new Exception($ex);
     }
     $auth = ldap_connect($this->config['host']);
     if (!$auth) {
         return false;
     }
     ldap_set_option($auth, LDAP_OPT_PROTOCOL_VERSION, 3);
     if (!@ldap_bind($auth, sprintf($this->config['bind_dn'], $username), $password)) {
         return false;
     }
     $_SESSION['valid'] = true;
     $_SESSION['user'] = $username;
     $_SESSION['admin'] = !$this->config['adminUser'] || $_SESSION['user'] == $this->config['adminUser'];
     $_SESSION['authCheckHeartbeat'] = time();
 }
开发者ID:enricowillemse,项目名称:prime_admin,代码行数:33,代码来源:LDAP.php

示例2: 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

示例3: getAllUsers

 public function getAllUsers()
 {
     // Settings for LDAP
     if ($this->container->hasParameter('ldap_host')) {
         $ldapHostname = $this->container->getParameter("ldap_host");
         $ldapPort = $this->container->getParameter("ldap_port");
         $ldapVersion = $this->container->getParameter("ldap_version");
         $baseDn = $this->container->getParameter("ldap_user_base_dn");
         $nameAttribute = $this->container->getParameter("ldap_user_name_attribute");
         $filter = "(" . $nameAttribute . "=*)";
         $connection = @ldap_connect($ldapHostname, $ldapPort);
         ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, $ldapVersion);
         $ldapListRequest = ldap_list($connection, $baseDn, $filter);
         // or throw exeption('Unable to list. LdapError: ' . ldap_error($ldapConnection));
         $ldapUserList = ldap_get_entries($connection, $ldapListRequest);
     }
     // Settings for local user database
     $repo = $this->getDoctrine()->getRepository('FOMUserBundle:User');
     $users = $repo->findAll();
     $all = array();
     if ($this->container->hasParameter('ldap_host')) {
         // Add Users from LDAP
         foreach ($ldapUserList as $ldapUser) {
             $user = new \stdClass();
             $user->getUsername = $ldapUser[$nameAttribute][0];
             $all[] = $user;
         }
     }
     // Add Mapbenderusers from database
     foreach ($users as $user) {
         $all[] = $user;
     }
     return $all;
 }
开发者ID:mapbender,项目名称:fom,代码行数:34,代码来源:FOMIdentitiesProvider.php

示例4: connect

 public function connect()
 {
     // connection already established
     if ($this->ds) {
         return true;
     }
     $this->bound = 0;
     if (!($this->ds = ldap_connect($this->cnf['host'], $this->cnf['port']))) {
         error('LDAP: couldn\'t connect to LDAP server.');
         return false;
     }
     // set protocol version and dependend options
     if ($this->cnf['version']) {
         if (!ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, $this->cnf['version'])) {
             error('Setting LDAP Protocol version ' . $this->cnf['version'] . ' failed.');
         } else {
             // use TLS (needs version 3)
             if (isset($this->cnf['starttls']) && !ldap_start_tls($this->ds)) {
                 error('Starting TLS failed.');
             }
             // needs version 3
             if (!zbx_empty($this->cnf['referrals']) && !ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $this->cnf['referrals'])) {
                 error('Setting LDAP referrals to off failed.');
             }
         }
     }
     // set deref mode
     if (isset($this->cnf['deref']) && !ldap_set_option($this->ds, LDAP_OPT_DEREF, $this->cnf['deref'])) {
         error('Setting LDAP Deref mode ' . $this->cnf['deref'] . ' failed.');
     }
     return true;
 }
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:32,代码来源:CLdap.php

示例5: _connect

 /**
  * Initiate LDAP connection.
  *
  * Not done in __construct(), only when a read or write action is
  * necessary.
  */
 protected function _connect()
 {
     if ($this->_ds) {
         return;
     }
     if (!($this->_ds = @ldap_connect($this->_params['server'], $this->_params['port']))) {
         throw new Turba_Exception(_("Connection failure"));
     }
     /* Set the LDAP protocol version. */
     if (!empty($this->_params['version'])) {
         @ldap_set_option($this->_ds, LDAP_OPT_PROTOCOL_VERSION, $this->_params['version']);
     }
     /* Set the LDAP deref option for dereferencing aliases. */
     if (!empty($this->_params['deref'])) {
         @ldap_set_option($this->_ds, LDAP_OPT_DEREF, $this->_params['deref']);
     }
     /* Set the LDAP referrals. */
     if (!empty($this->_params['referrals'])) {
         @ldap_set_option($this->_ds, LDAP_OPT_REFERRALS, $this->_params['referrals']);
     }
     /* Start TLS if we're using it. */
     if (!empty($this->_params['tls']) && !@ldap_start_tls($this->_ds)) {
         throw new Turba_Exception(sprintf(_("STARTTLS failed: (%s) %s"), ldap_errno($this->_ds), ldap_error($this->_ds)));
     }
     /* Bind to the server. */
     if (isset($this->_params['bind_dn']) && isset($this->_params['bind_password'])) {
         $error = !@ldap_bind($this->_ds, $this->_params['bind_dn'], $this->_params['bind_password']);
     } else {
         $error = !@ldap_bind($this->_ds);
     }
     if ($error) {
         throw new Turba_Exception(sprintf(_("Bind failed: (%s) %s"), ldap_errno($this->_ds), ldap_error($this->_ds)));
     }
 }
开发者ID:DSNS-LAB,项目名称:Dmail,代码行数:40,代码来源:Ldap.php

示例6: setoptions

 private function setoptions($handle, $configuration)
 {
     ldap_set_option($handle, LDAP_OPT_PROTOCOL_VERSION, $configuration['protocol']);
     ldap_set_option($handle, LDAP_OPT_REFERRALS, $configuration['referrals']);
     ldap_set_option($handle, LDAP_OPT_TIMELIMIT, $configuration['timelimit']);
     ldap_set_option($handle, LDAP_OPT_NETWORK_TIMEOUT, $configuration['timeout']);
 }
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:7,代码来源:openldap.php

示例7: 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

示例8: connect

 /**
  * Tries to connect to an LDAP server.
  *
  * If a connection is currently open, it is closed.
  *
  * All PHP errors triggered by ldap_* calls are wrapped in exceptions and thrown.
  *
  * @param string $serverHostName The hostname of the LDAP server.
  * @param int $port The server port to use.
  * @param int $timeout The timeout in seconds of the network connection.
  * @throws Exception If an error occurs during the `ldap_connect` call or if there is a connection
  *                   issue during the subsequent anonymous bind.
  */
 public function connect($serverHostName, $port = ServerInfo::DEFAULT_LDAP_PORT, $timeout = self::DEFAULT_TIMEOUT_SECS)
 {
     $this->closeIfCurrentlyOpen();
     Log::debug("Calling ldap_connect('%s', %s)", $serverHostName, $port);
     $this->connectionResource = ldap_connect($serverHostName, $port);
     ldap_set_option($this->connectionResource, LDAP_OPT_PROTOCOL_VERSION, 3);
     ldap_set_option($this->connectionResource, LDAP_OPT_REFERRALS, 0);
     ldap_set_option($this->connectionResource, LDAP_OPT_NETWORK_TIMEOUT, $timeout);
     Log::debug("ldap_connect result is %s", $this->connectionResource);
     // ldap_connect will not always try to connect to the server, so execute a bind
     // to test the connection
     try {
         ldap_bind($this->connectionResource);
         Log::debug("anonymous ldap_bind call finished; connection ok");
     } catch (Exception $ex) {
         // if the error was due to a connection error, rethrow, otherwise ignore it
         $errno = ldap_errno($this->connectionResource);
         Log::debug("anonymous ldap_bind returned error '%s'", $errno);
         if (!in_array($errno, self::$initialBindErrorCodesToIgnore)) {
             throw $ex;
         }
     }
     if (!$this->isOpen()) {
         // sanity check
         throw new Exception("sanity check failed: ldap_connect did not return a connection resource!");
     }
 }
开发者ID:polytan02,项目名称:dev_piwik_ynh,代码行数:40,代码来源:Client.php

示例9: LDAPLogin

function LDAPLogin($server = "mydomain.local", $username, $password, $domain = "mydomain", $dc = "dc=mydomain,dc=local")
{
    // https://www.exchangecore.com/blog/how-use-ldap-active-directory-authentication-php/
    $ldap = ldap_connect("ldap://{$server}");
    $ldaprdn = "{$domain}\\{$username}";
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
    $bind = @ldap_bind($ldap, $ldaprdn, $password);
    if ($bind) {
        $filter = "(sAMAccountName={$username})";
        $result = ldap_search($ldap, $dc, $filter);
        ldap_sort($ldap, $result, "sn");
        $info = ldap_get_entries($ldap, $result);
        if (!isset($info[0]["mail"][0])) {
            Log::createLog("danger", "ldap", "Unable to query LDAP, check base settings.");
            return null;
        }
        $data = array();
        $data["email"] = $info[0]["mail"][0];
        $data["lastname"] = $info[0]["sn"][0];
        $data["firstname"] = $info[0]["givenname"][0];
        @ldap_close($ldap);
        return $data;
    } else {
        Log::createLog("danger", "ldap", "Error: " . ldap_error($ldap));
    }
    return null;
}
开发者ID:DeltaWolf7,项目名称:Arc,代码行数:28,代码来源:login.php

示例10: connect

 private function connect()
 {
     $port = isset($this->params['client']['port']) ? $this->params['client']['port'] : '389';
     $ress = @ldap_connect($this->params['client']['host'], $port);
     if (isset($this->params['client']['version']) && $this->params['client']['version'] !== null) {
         ldap_set_option($ress, LDAP_OPT_PROTOCOL_VERSION, $this->params['client']['version']);
     }
     if (isset($this->params['client']['referrals_enabled']) && $this->params['client']['referrals_enabled'] !== null) {
         ldap_set_option($ress, LDAP_OPT_REFERRALS, $this->params['client']['referrals_enabled']);
     }
     if (isset($this->params['client']['username']) && $this->params['client']['version'] !== null) {
         if (!isset($this->params['client']['password'])) {
             throw new \Exception('You must uncomment password key');
         }
         $bindress = @ldap_bind($ress, $this->params['client']['username'], $this->params['client']['password']);
         if (!$bindress) {
             throw new \Exception('The credentials you have configured are not valid');
         }
     } else {
         $bindress = @ldap_bind($ress);
         if (!$bindress) {
             throw new \Exception('Unable to connect Ldap');
         }
     }
     $this->_ress = $ress;
     return $this;
 }
开发者ID:rtoledof,项目名称:LdapBundle,代码行数:27,代码来源:LdapConnection.php

示例11: bind

 private function bind($authenticated = false)
 {
     if ($this->connected) {
         if ($authenticated && !$this->authenticated) {
             ldap_bind($this->connection, $this->config['username'] . ',' . $this->config['dn'], $this->config['password']);
         }
         return;
     }
     ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
     try {
         $connection = ldap_connect($this->config['host']);
         // Change protocol
         ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
         ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
         if ($authenticated) {
             ldap_bind($connection, $this->config['username'] . ',' . $this->config['dn'], $this->config['password']);
         }
         // Start TLS
         // ldap_start_tls($connection);
     } catch (Exception $e) {
         print_r($e);
         return;
     }
     $this->connected = true;
     $this->connection = $connection;
 }
开发者ID:thibmo,项目名称:hackthis.co.uk,代码行数:26,代码来源:class.ldap.php

示例12: __construct

 /**
  * Connection to the database
  *
  */
 public function __construct()
 {
     $this->domain = $domain;
     parent::__construct();
     require FRAMEWORK . DS . 'conf' . DS . 'datastore.php';
     $config = $datastore[$this->datastore];
     if (!isset(self::$connection[$this->datastore])) {
         self::$connection[$this->datastore] = @ldap_connect($config['protocol'] . $config['domain']);
         if (!self::$connection[$this->datastore]) {
             throw new connectException('Could not connect to the Active Directory.');
         }
         ldap_set_option(self::$connection[$this->datastore], LDAP_OPT_REFERRALS, 0);
         ldap_set_option(self::$connection[$this->datastore], LDAP_OPT_PROTOCOL_VERSION, 3);
         if (!@ldap_bind(self::$connection[$this->datastore], $config['user'] . '@' . $config['domain'], $config['password'])) {
             throw new connectException('Could not bind to the Active Directory.');
         }
     }
     $this->con =& self::$connection[$this->datastore];
     $this->dn = $config['dn'];
     $config2 = $datastore[$this->datastore2];
     if (!isset(self::$connection[$this->datastore2])) {
         self::$connection[$this->datastore2] = @ldap_connect($config2['protocol'] . $config2['domain']);
         if (!self::$connection[$this->datastore2]) {
             throw new connectException('Could not connect to the Active Directory.');
         }
         ldap_set_option(self::$connection[$this->datastore2], LDAP_OPT_REFERRALS, 0);
         ldap_set_option(self::$connection[$this->datastore2], LDAP_OPT_PROTOCOL_VERSION, 3);
         if (!@ldap_bind(self::$connection[$this->datastore2], $config2['user'] . '@' . $config2['domain'], $config2['password'])) {
             throw new connectException('Could not bind to the Active Directory.');
         }
     }
     $this->con2 =& self::$connection[$this->datastore2];
     $this->dn2 = $config2['dn'];
     $this->attributes = array_keys($this->mapping);
 }
开发者ID:nephie,项目名称:AZL-website,代码行数:39,代码来源:admodel.php

示例13: __construct

 /**
  * Constructor
  */
 function __construct()
 {
     $this->ds = ldap_connect($this->host);
     ldap_set_option($this->ds, LDAP_OPT_REFERRALS, 0);
     ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
     ldap_bind($this->ds, $this->user, $this->pass);
 }
开发者ID:neohusky,项目名称:NMIS,代码行数:10,代码来源:activedirectory.php

示例14: ldap_authenticate

function ldap_authenticate($user, $pass)
{
    // Global variables
    global $ldap_base_DN, $ldap_server, $template, $admin_users, $ldap_user_cn;
    // Connect to the LDAP server
    $conn = ldap_connect($ldap_server) or die("Cannot connect");
    ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
    // Bind anonymously, query the server for the user, and error if it can't be found
    if (!($bind = ldap_bind($conn))) {
        $template['message'] = "<p>Anonymous bind failed.</p>";
        return;
    }
    // Do a search for the username and get the DN - this is easier than manually constructing it
    if (!($search = ldap_search($conn, $ldap_base_DN, "{$ldap_user_cn}={$user}"))) {
        $template['message'] = "<p><strong>Error:</strong> Could not find the username.</p>";
        return;
    }
    // If there isn't only one row.
    if (ldap_count_entries($conn, $search) != 1) {
        $template['message'] = "<p>There was an error processing the username, or it cannot be found.</p>";
        return;
    }
    // Extract the entries, and bind with the user's full DN, then unset the password for security
    $entries = @ldap_get_entries($conn, $search);
    $bind_auth = @ldap_bind($conn, $entries[0]['dn'], $pass);
    unset($pass);
    // If we have a successful bind, add the relevant session information
    if ($bind_auth) {
        $_SESSION['admin'] = in_array($user, $admin_users);
        $_SESSION['username'] = $user;
        header('Location: index.php');
    } else {
        $template['message'] = "<p><strong>Login failed.</strong> Please try again.</p>";
    }
}
开发者ID:smm13344331,项目名称:openbooking,代码行数:35,代码来源:functions_login.php

示例15: getADConnection

 private static function getADConnection($username = null, $password = null)
 {
     if (!function_exists("ldap_connect")) {
         return null;
     }
     $LD = LoginData::get("ADServerUserPass");
     if ($LD == null) {
         return null;
     }
     $adServer = "ldap://" . $LD->A("server");
     $ex = explode("@", $LD->A("benutzername"));
     if ($username == null) {
         $username = $LD->A("benutzername");
     } else {
         $username = $username . "@" . $ex[1];
     }
     if ($password == null) {
         $password = $LD->A("passwort");
     }
     $ldap = ldap_connect($adServer);
     ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
     ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
     $bind = ldap_bind($ldap, $username, $password);
     if (!$bind) {
         throw new Exception("Keine Verbindung zu AD-Server");
     }
     return $ldap;
 }
开发者ID:nemiah,项目名称:poolPi,代码行数:28,代码来源:LoginAD.class.php


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