-
Notifications
You must be signed in to change notification settings - Fork 71
/
ldap.php
62 lines (49 loc) · 1.81 KB
/
ldap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
error_reporting(E_ALL);
###################################---Configuration---################################
// Ldap adress and port
$hostname = "ldap://localhost:389";
// LDAP version
$ldap_version = 3;
// User identifier - UID
$uid = "jdoe";
// Bind directory name
$bind_dn = "cn=butler,dc=example,dc=com";
// Bind password
$bind_pass = "readonly";
// Base directory name
$base = "ou=People,dc=example,dc=com";
######################################################################################
echo "<h3>LDAP : Test Center</h3>";
echo "Attempting to connect LDAP server ... <br />";
$ldap=ldap_connect($hostname);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $ldap_version);
if ($ldap) {
echo "Successful connection ! <br />";
echo "Authenticating with bind credentials ... <br />";
$is_valid=ldap_bind($ldap,$bind_dn,$bind_pass);
if ($is_valid) {
echo "Successful authentication ! <br />";
echo "Getting user informations ...<br />";
$user_data=ldap_search($ldap, $base, "uid=" . $uid);
if ($user_data) {
echo "Data recovered with success ! <br />";
echo "Extracting useful data : <br /><br />";
$info_user = ldap_get_entries($ldap, $user_data);
for ($i=0; $i<$info_user["count"]; $i++) {
echo "dn: " . $info_user[$i]["dn"] . "<br />";
echo "cn: " . $info_user[$i]["cn"][0] . "<br />";
echo "uid: " . $info_user[$i]["uid"][0] . "<br />";
echo "email: " . $info_user[$i]["mail"][0] . "<br /><hr />";
}
} else {
echo "No data recovered ! <br /><br />";
}
} else {
echo "Identification has failed ... Check bind credentials<br /><br />";
}
echo "Closing LDAP connection.";
ldap_close($ldap);
} else {
echo "Impossible to connect to LDAP server !";
}