Инструменты пользователя

Инструменты сайта


programming:php:ldap-test

LDAP test

<!--
---- php-ldap.php (0644): server example PHP/LDAP code
--->

<?php

echo "<html><head><title>PHP/LDAP Query Test</title></head><body>";

$lc = ldap_connect("127.0.0.1");

ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, 3);

if (!ldap_start_tls($lc)) {
  echo "<h1>Unable to connect to the LDAP server!</h1>";
  echo "</body></html>";
  exit;
}

echo "<h1>LDAP query results</h1>";

ldap_bind($lc);

// Search users in the group with gid 100
$base = "ou=People,dc=intra";
$filt = "gidNumber=100";
$sr = ldap_search($lc, $base, $filt);
$info = ldap_get_entries($lc, $sr);

echo "Searched from base " . $base . " with filter " . $filt . ".<br><br>";

for ($i = 0; $i < $info["count"]; $i++) {
  echo "Match " . $i . ": " . $info[$i]["cn"][0];
  echo " (e-mail: " . $info[$i]["mail"][0] . ")<br>";
}

if ($i == 0) {
  echo "No matches found!";
}

ldap_close($lc);

echo "</body></html>";

?>
programming/php/ldap-test.txt · Последнее изменение: 2017/03/27 11:26 — artur

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki