| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- $ini = parse_ini_file('../includes/config.ini');
- function get_ldap_conn() {
- try {
- global $ini;
- $ldapconn = ldap_connect($ini['hostname'], $ini['port']);
- ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
- ldap_start_tls($ldapconn);
- } catch (Exception $e) {
- die ('ERROR: ' . $e->getMessage());
- }
- return $ldapconn;
- }
- function bind_as_user($id, $passwd) {
- global $ini;
- $ldapconn = get_ldap_conn();
- if (!$ldapconn) {
- return false;
- }
- $res = @ldap_bind($ldapconn, "uid=" . $id . ',' . $ini["basedn"], $passwd);
- return array($res, $ldapconn);
- }
- function bind_as_operator() {
- global $ini;
- $ldapconn = get_ldap_conn();
- if (!$ldapconn) {
- return false;
- }
- $res = @ldap_bind($ldapconn, $ini["binddn"], $ini["bindpw"]);
- return array($res, $ldapconn);
- }
|