I have around 12 PHP functions, each one makes a call to $ldap_connect which makes use of ldap_bind()
So - does this mean that when I call all functions my ldap server makes 12 ldap binds?
If so - when should the ldap_unbind() function be used? I have tried searching this but nothing fruitful came up, all I seemed to find was "unbind every time" but that isn't really specific. Does that mean put an unbind in all 12 functions just before it returns the data or unbind on my logout page where I also do a session_destroy() ?
Thanks
EDIT: CODE
function create_ldap_connection($username, $password) {
$ip = "MY LDAP SERVER";
$port = 389;
/* Binding */
$username = "DOMAIN\\" . $username;
$ldap_conn = ldap_connect($ip, $port) or die("Sorry! Could not connect to LDAP server ($ip)");
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Couldn't set option version 3");
$starttls = ldap_start_tls($ldap_conn) or die ("Couldn't start secure TLS connection");
$result = ldap_bind($ldap_conn, $username, $password) or die("Error: Couldn't bind to server using provided credentials!");
if($result) {
return $ldap_conn;
} else {
die("
Error: Couldn't bind to server with supplied credentials!");
}
}
Then I use $ldap_conn = create_ldap_connection($user, $pass);
So, my 2 of my functions would be:
function get_user_givenName($ldap_conn, $user_name, $ou) {
$basedn = "MY BASE DN";
$searchResults = ldap_search($ldap_conn, $basedn, $user_name);
if (!is_resource($searchResults))
die('Error in search results.');
$entry = ldap_first_entry($ldap_conn, $searchResults);
$attrs = ldap_get_attributes($ldap_conn, $entry);
return $attrs["givenName"][0];
}
function get_user_cn($ldap_conn, $user_name, $ou) {
$basedn = "MY BASE DN";
$searchResults = ldap_search($ldap_conn, $basedn, $user_name);
if (!is_resource($searchResults))
die('Error in search results.');
$entry = ldap_first_entry($ldap_conn, $searchResults);
$attrs = ldap_get_attributes($ldap_conn, $entry);
return $attrs["cn"][0];
}