本文整理汇总了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;
}
示例2: disconnect
private function disconnect()
{
if ($this->connection && is_resource($this->connection)) {
ldap_close($this->connection);
}
$this->connection = null;
}
示例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;
}
}
示例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>";
}
}
示例5: close
/**
* Closing the connection
*/
function close()
{
if ($this->_connection !== null) {
ldap_close($this->_connection);
$this->_connection = null;
}
}
示例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);
}
示例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;
}
}
示例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;
}
示例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";
}
}
示例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;
}
示例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 : '';
}
示例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;
}
示例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;
}
示例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);
}
示例15: _encrypt
function _encrypt($str_userpswd)
{
echo '<h3>Prueba de consulta LDAP</h3>';
echo 'Conectando ...';
$ds = ldap_connect('localhost');
echo 'El resultado de la conexión es ' . $ds . '<p>';
if ($ds) {
echo 'Autentificándose ...';
$r = ldap_bind($ds);
echo 'El resultado de la autentificación es ' . $r . '<p>';
echo 'Buscando (sn=P*) ...';
$sr = ldap_search($ds, 'o=halys, c=halys', 'sn=h*');
echo 'El resultado de la búsqueda es ' . $sr . '<p>';
echo 'El número de entradas devueltas es ' . ldap_count_entries($ds, $sr) . '<p>';
echo 'Recuperando entradas ...<p>';
$info = ldap_get_entries($ds, $sr);
echo 'Devueltos datos de ' . $info['count'] . ' entradas:<p>';
for ($i = 0; $i < $info['count']; $i++) {
echo 'dn es: ' . $info[$i]['dn'] . '<br>';
echo 'La primera entrada cn es: ' . $info[$i]['cn'][0] . '<br>';
}
echo 'Cerrando conexión';
ldap_close($ds);
} else {
echo '<h4>Ha sido imposible conectar al servidor LDAP</h4>';
}
}