-
Notifications
You must be signed in to change notification settings - Fork 0
/
adodbLdap.php
executable file
·62 lines (42 loc) · 1.68 KB
/
adodbLdap.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
<?php
require('adodb/adodb.inc.php');
/* Make sure to set this BEFORE calling Connect() */
$LDAP_CONNECT_OPTIONS = Array(
Array ("OPTION_NAME"=>LDAP_OPT_DEREF, "OPTION_VALUE"=>2),
Array ("OPTION_NAME"=>LDAP_OPT_SIZELIMIT,"OPTION_VALUE"=>100),
Array ("OPTION_NAME"=>LDAP_OPT_TIMELIMIT,"OPTION_VALUE"=>30),
Array ("OPTION_NAME"=>LDAP_OPT_PROTOCOL_VERSION,"OPTION_VALUE"=>3),
Array ("OPTION_NAME"=>LDAP_OPT_ERROR_NUMBER,"OPTION_VALUE"=>13),
Array ("OPTION_NAME"=>LDAP_OPT_REFERRALS,"OPTION_VALUE"=>FALSE),
Array ("OPTION_NAME"=>LDAP_OPT_RESTART,"OPTION_VALUE"=>FALSE)
);
$host = '192.168.2.1';
$ldapbase = 'ou=People,dc=empresa,dc=com,dc=br';
$ldap = NewADOConnection( 'ldap' );
$ldap->Connect( $host, $user_name='cn=Manager,dc=empresa,dc=com,dc=br', $password='tux', $ldapbase );
//Adicionei esta linha para se for necessário logar um usuário pode-se pesquisar no banco
//$passwd = "{MD5}".base64_encode(pack("H*",md5($_POST["senha"])));
$userName = &_POST["usuario"];
echo "<pre>";
//imprime os dados do servidor
print_r( $ldap->ServerInfo() );
$ldap->SetFetchMode(ADODB_FETCH_ASSOC);
$filter="(|(cn=$userName*)(sn=$userName*)(givenname=$userName*)(uid=$userName*))";
$rs = $ldap->Execute( $filter );
if ($rs)
while ($arr = $rs->FetchRow()) {
print_r($arr);
}
$rs = $ldap->Execute( $filter );
if ($rs)
while (!$rs->EOF) {
print_r($rs->fields);
$rs->MoveNext();
}
print_r( $ldap->GetArray( $filter ) );
print_r( $ldap->GetRow( $filter ) );
//Variável para debugar o código
//$ldap->debug=true;
$ldap->Close();
echo "</pre>";
?>