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


PHP ldap_close函数代码示例

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


在下文中一共展示了ldap_close函数的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: disconnect

 private function disconnect()
 {
     if ($this->connection && is_resource($this->connection)) {
         ldap_close($this->connection);
     }
     $this->connection = null;
 }
开发者ID:robinkanters,项目名称:symfony,代码行数:7,代码来源:Connection.php

示例3: validate

 /**
  *  This function take user-provided login and password, and tries
  *  an to authenticate this user using the LDAP server set in
  *  config.php.
  *
  *  @param login the login provided by the user
  *  @param password the password provided by the user
  *  @returns false if the authentification fails, or the username if
  *           it succeeds.
  */
 function validate($login, $password)
 {
     //echo "\$login : $login<br />\n";
     //echo "\$password : $password<br />\n";
     // Connect to the ldap server
     $this->connectionID = ldap_connect($this->ldapServer);
     // First, bind anonymously and retrieve the full DN corresponding to
     // the login provided by the user, as well as the user name to display.
     $success = ldap_bind($this->connectionID);
     $searchString = "(&(objectClass=person)({$this->ldapSearchAttribute}={$login}))";
     $result = ldap_search($this->connectionID, $this->ldapBase, $searchString, array("dn", $this->userNameAttribute));
     $entries = ldap_get_entries($this->connectionID, $result);
     // Keep only the first entry
     $userFullDN = $entries[0]["dn"];
     $userNameToDisplay = $entries[0]["{$this->userNameAttribute}"][0];
     // If $userNameToDisplay retrievial failed, we won't authenticate, so
     // set it to true to save things.
     if (empty($userNameToDisplay)) {
         $userNameToDisplay = true;
     }
     // TODO GESTION D'ERREUR !
     // Now we can authenticate : Bind to the ldap server
     $success = ldap_bind($this->connectionID, $userFullDN, $password);
     ldap_close($this->connectionID);
     // If bind was successful, then authentification succeeded too, and return
     // the user name to display.
     if ($success == true) {
         return $userNameToDisplay;
     } else {
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:jasmine-svn,代码行数:42,代码来源:init.php

示例4: ldap_call

function ldap_call($connection, $bind_user, $bind_pass, $filter)
{
    $ds = ldap_connect($connection);
    if ($ds) {
        $r = ldap_bind($ds, $bind_user, $bind_pass);
        //$filter="(|(mail= null)(objectCategory=group))";
        $sr = ldap_search($ds, "ou=LMC, dc=lamontanita, dc=local", $filter);
        ldap_sort($ds, $sr, "cn");
        $info = ldap_get_entries($ds, $sr);
        //echo $info["count"] . " results returned:<p>";
        /*	echo "<table id='ldaptable' border=1><tr><th>Name</th><th>E-mail</th></tr>";
            for ($i=0; $i<$info["count"]; $i++) {
            		if($info[$i]["mail"][0]!=null){
                echo "<td>". $info[$i]["cn"][0] . "</td>";
                echo "<td>" . $info[$i]["mail"][0] . "</td></tr>";
            }
            }    
        	echo "</table>";*/
        echo '<pre>';
        print_r($info);
        return $info;
        ldap_close($ds);
    } else {
        echo "<h4>LDAP_CALL unable to connect to LDAP server</h4>";
    }
}
开发者ID:stpmt11,项目名称:phpos,代码行数:26,代码来源:ldapreadout.php

示例5: close

 /**
  * Closing the connection
  */
 function close()
 {
     if ($this->_connection !== null) {
         ldap_close($this->_connection);
         $this->_connection = null;
     }
 }
开发者ID:BackupTheBerlios,项目名称:phpannu-svn,代码行数:10,代码来源:CopixLdapConnection.class.php

示例6: my_session_login

function my_session_login($username, $password)
{
    $domain = $GLOBALS['config']['my_ad_domain'];
    if (strpos($username, "\\")) {
        list($domain, $username) = explode("\\", $username, 2);
    }
    $domain = preg_replace("/[^0-9A-Za-z \\-\\.]/", "", $domain);
    $username = preg_replace("/[^0-9A-Za-z \\-\\.]/", "", $username);
    $ldap = ldap_connect($GLOBALS['config']['my_ad_server']);
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
    $bind = @ldap_bind($ldap, $domain . "\\" . $username, $password);
    if (!$bind) {
        show_error("Invalid username and/or password.");
    }
    $result = ldap_search($ldap, $GLOBALS['config']['my_ad_basedn'], "(sAMAccountName={$username})");
    $info = ldap_get_entries($ldap, $result);
    @ldap_close($ldap);
    if ($info['count'] != 1) {
        show_error("Account not found.");
    }
    $_SESSION['username'] = my_encrypt($info[0]["samaccountname"][0]);
    $_SESSION['fullname'] = my_encrypt($info[0]["displayname"][0]);
    $_SESSION['last_seen'] = my_encrypt(time());
    $_SESSION['user_agent'] = my_encrypt($_SERVER['HTTP_USER_AGENT']);
    $action = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
    header("Location: " . $action);
}
开发者ID:JasonSFuller,项目名称:depot,代码行数:28,代码来源:index.php

示例7: _processLogin

 /**
  * 
  * Verifies a username handle and password.
  * 
  * @return mixed An array of verified user information, or boolean false
  * if verification failed.
  * 
  * 
  */
 protected function _processLogin()
 {
     // connect
     $conn = @ldap_connect($this->_config['uri']);
     // did the connection work?
     if (!$conn) {
         throw $this->_exception('ERR_CONNECTION_FAILED', $this->_config);
     }
     // upgrade to LDAP3 when possible
     @ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
     // filter the handle to prevent LDAP injection
     $regex = '/[^' . $this->_config['filter'] . ']/';
     $this->_handle = preg_replace($regex, '', $this->_handle);
     // bind to the server
     $rdn = sprintf($this->_config['format'], $this->_handle);
     $bind = @ldap_bind($conn, $rdn, $this->_passwd);
     // did the bind succeed?
     if ($bind) {
         ldap_close($conn);
         return array('handle' => $this->_handle);
     } else {
         $this->_err = @ldap_errno($conn) . " " . @ldap_error($conn);
         ldap_close($conn);
         return false;
     }
 }
开发者ID:agentile,项目名称:foresmo,代码行数:35,代码来源:Ldap.php

示例8: ldap

 /**
  * Authenticates a user to LDAP
  *
  * @param $username
  * @param $password
  * @param bool|false $returnUser
  * @return bool true    if the username and/or password provided are valid
  *              false   if the username and/or password provided are invalid
  *         array of ldap_attributes if $returnUser is true
  */
 function ldap($username, $password, $returnUser = false)
 {
     $ldaphost = Setting::getSettings()->ldap_server;
     $ldaprdn = Setting::getSettings()->ldap_uname;
     $ldappass = Crypt::decrypt(Setting::getSettings()->ldap_pword);
     $baseDn = Setting::getSettings()->ldap_basedn;
     $filterQuery = Setting::getSettings()->ldap_auth_filter_query . $username;
     $ldapversion = Setting::getSettings()->ldap_version;
     // Connecting to LDAP
     $connection = ldap_connect($ldaphost) or die("Could not connect to {$ldaphost}");
     // Needed for AD
     ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
     ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, $ldapversion);
     try {
         if ($connection) {
             // binding to ldap server
             $ldapbind = ldap_bind($connection, $ldaprdn, $ldappass);
             if (($results = @ldap_search($connection, $baseDn, $filterQuery)) != false) {
                 $entry = ldap_first_entry($connection, $results);
                 if (($userDn = @ldap_get_dn($connection, $entry)) !== false) {
                     if (($isBound = ldap_bind($connection, $userDn, $password)) == "true") {
                         return $returnUser ? array_change_key_case(ldap_get_attributes($connection, $entry), CASE_LOWER) : true;
                     }
                 }
             }
         }
     } catch (Exception $e) {
         LOG::error($e->getMessage());
     }
     ldap_close($connection);
     return false;
 }
开发者ID:chromahoen,项目名称:snipe-it,代码行数:42,代码来源:AuthController.php

示例9: connect

 public function connect()
 {
     // basic sequence with LDAP is connect, bind, search, interpret search
     // result, close connection
     $ds = ldap_connect("192.168.0.111");
     // must be a valid LDAP server!
     if ($ds) {
         $r = ldap_bind($ds, "portalusr01", "tbs4portal");
         // this is an "anonymous" bind, typically
         if (!$r) {
             echo "Unable to connect to LDAP server";
             die;
         }
         // Search surname entry
         //			$dn = "OU=Users,OU=PT. Monica Hijau Lestari,DC=thebodyshop,DC=co,DC=id";
         $dn = "OU=Users,OU=ho-bintaro,DC=thebodyshop,DC=co,DC=id";
         $filter = "(|(SN=*)(CN=*))";
         $sr = ldap_search($ds, $dn, $filter);
         $info = ldap_get_entries($ds, $sr);
         $dn = "OU=user,OU=warehouse-bsd,DC=thebodyshop,DC=co,DC=id";
         $filter = "(|(SN=*)(CN=*))";
         $sr = ldap_search($ds, $dn, $filter);
         $infoDc = ldap_get_entries($ds, $sr);
         $this->parseUsers($info, $infoDc);
         ldap_close($ds);
     } else {
         echo "Unable to connect to LDAP server";
     }
 }
开发者ID:CapsuleCorpIndonesia,项目名称:es-teler-baru-suka,代码行数:29,代码来源:Ldap.php

示例10: is_prof

function is_prof($login)
{
    global $ldap_server, $ldap_port, $dn;
    global $error;
    $error = "";
    $filter = "(&(cn=profs*)(memberUid={$login}))";
    $ldap_groups_attr = array("cn", "memberUid");
    /*-----------------------------------------------------*/
    $ds = @ldap_connect($ldap_server, $ldap_port);
    if ($ds) {
        $r = @ldap_bind($ds);
        if (!$r) {
            $error = "Echec du bind anonyme";
        } else {
            // Recherche du groupe d'appartenance de l'utilisateur connecte
            $result = @ldap_list($ds, $dn["groups"], $filter, $ldap_groups_attr);
            if ($result) {
                $info = @ldap_get_entries($ds, $result);
                if ($info["count"]) {
                    $is_prof = true;
                } else {
                    $is_prof = false;
                }
            }
        }
    }
    @ldap_unbind($ds);
    @ldap_close($ds);
    return $is_prof;
}
开发者ID:rhertzog,项目名称:lcs,代码行数:30,代码来源:init_users_lcs.php

示例11: getOrganizations

 private function getOrganizations()
 {
     // Common functions
     $common = new common();
     // Ldap Connections
     $ldap = $common->ldapConnect($this->ldap_host, $this->ldap_root_dn, $this->ldap_root_pw);
     if ($ldap) {
         $filter = "objectClass=organizationalUnit";
         $justthese = array("ou");
         $search = ldap_list($ldap, $this->ldap_context, $filter, $justthese);
         $entry = ldap_get_entries($ldap, $search);
     }
     if ($entry['count'] > 0) {
         foreach ($entry as $tmp) {
             if ($tmp['ou'][0] != "") {
                 $result_ou[] = $tmp['ou'][0];
             }
         }
     } else {
         $result_ou[] = $this->ldap_context;
     }
     natcasesort($result_ou);
     ldap_close($ldap);
     return $result_ou ? $result_ou : '';
 }
开发者ID:cjvaz,项目名称:expressomail,代码行数:25,代码来源:class.configMessenger.inc.php

示例12: checkAdLoginAuth

function checkAdLoginAuth($user_id, $login_passwd)
{
    //接続開始
    $ldap_conn = ldap_connect(LDAP_HOST_1, LDAP_PORT);
    if (!$ldap_conn) {
        $ldap_conn = ldap_connect("ldaps://" . LDAP_HOST_2);
    } else {
        print_r("OK" . PHP_EOL);
    }
    if (!$ldap_conn) {
        Debug_Trace("接続失敗");
        return false;
    }
    if ($ldap_conn) {
        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
        $ldap_bind = ldap_bind($ldap_conn, "CN=" . $user_id . "," . LDAP_DN, $login_passwd);
        if ($ldap_bind) {
            Debug_Trace("ADの認証に成功しました", 3);
            return true;
        } else {
            Debug_Trace("ADの認証に失敗しました", 3);
            Debug_Trace($user_id, 3);
            return false;
        }
    } else {
        Debug_Trace('ADサーバへの接続に失敗しました');
        return false;
    }
    ldap_close($ldap_conn);
    return true;
}
开发者ID:honda-kyoto,项目名称:UMS-Kyoto,代码行数:31,代码来源:test_ad_bind2.php

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

示例14: ldap_auth

function ldap_auth()
{
    $ldap_server = 'ldap://127.0.0.1/';
    $ldap_domain = 'dc=rugion,dc=ru';
    //$ldap_userbase = 'ou=users,ou=chelyabinsk,' . $ldap_domain;
    //$ldap_user = 'uid=' . $_SERVER['PHP_AUTH_USER'] . ',' . $ldap_userbase;
    $ldap_user = ' ';
    $ldap_pass = $_SERVER['PHP_AUTH_PW'];
    $ldapconn_s = ldap_connect($ldap_server) or die("Could not connect to LDAP server.");
    ldap_set_option($ldapconn_s, LDAP_OPT_PROTOCOL_VERSION, 3);
    if ($ldapconn_s) {
        $ldapbind_s = @ldap_bind($ldapconn_s);
        $result = ldap_search($ldapconn_s, $ldap_domain, "(&(uid=" . $_SERVER['PHP_AUTH_USER'] . ")(objectClass=sambaSamAccount)(!(sambaAcctFlags=[DU ])))");
        $info = ldap_get_entries($ldapconn_s, $result);
        $ldap_user = $info[0]["dn"];
    }
    ldap_close($ldapconn_s);
    // connect to ldap server
    $ldapconn = ldap_connect($ldap_server) or die("Could not connect to LDAP server.");
    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
    if ($ldapconn) {
        // try to bind/authenticate against ldap
        $ldapbind = @ldap_bind($ldapconn, $ldap_user, $ldap_pass) || forbidden();
        // "LDAP bind successful...";
        error_log("success: " . $_SERVER['REMOTE_ADDR'] . ', user: ' . $_SERVER['PHP_AUTH_USER']);
    }
    ldap_close($ldapconn);
}
开发者ID:le9i0nx,项目名称:ansible-root,代码行数:28,代码来源:ldap-auth.php

示例15: _encrypt

 function _encrypt($str_userpswd)
 {
     echo '&lt;h3>Prueba de consulta LDAP&lt;/h3>';
     echo 'Conectando ...';
     $ds = ldap_connect('localhost');
     echo 'El resultado de la conexi&oacute;n es ' . $ds . '&lt;p>';
     if ($ds) {
         echo 'Autentific&aacute;ndose  ...';
         $r = ldap_bind($ds);
         echo 'El resultado de la autentificaci&oacute;n es ' . $r . '&lt;p>';
         echo 'Buscando (sn=P*) ...';
         $sr = ldap_search($ds, 'o=halys, c=halys', 'sn=h*');
         echo 'El resultado de la b&uacute;squeda es ' . $sr . '&lt;p>';
         echo 'El n&uacute;mero de entradas devueltas es ' . ldap_count_entries($ds, $sr) . '&lt;p>';
         echo 'Recuperando entradas ...&lt;p>';
         $info = ldap_get_entries($ds, $sr);
         echo 'Devueltos datos de ' . $info['count'] . ' entradas:&lt;p>';
         for ($i = 0; $i < $info['count']; $i++) {
             echo 'dn es: ' . $info[$i]['dn'] . '&lt;br>';
             echo 'La primera entrada cn es: ' . $info[$i]['cn'][0] . '&lt;br>';
         }
         echo 'Cerrando conexi&oacute;n';
         ldap_close($ds);
     } else {
         echo '&lt;h4>Ha sido imposible conectar al servidor LDAP&lt;/h4>';
     }
 }
开发者ID:BackupTheBerlios,项目名称:migueloo,代码行数:27,代码来源:base_loginldap.class.php


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