- foreach ($cpw_ldap_connect_opts as $opt => $value) {
- if (! ldap_set_option($cpw_ldap_con,constant('LDAP_OPT_' . $opt),$value)) {
- // set error message
- array_push($msgs,sprintf(_("Setting of ldap connection option %s to value %s failed."),$opt,$value));
- // FIXME: check if ldap_set_option modifies ldap_error.
- array_push($msgs,sprintf(_("Error: %s"),ldap_error($cpw_ldap_con)));
- $cpw_ldap_con_err=true;
+ // ldap_set_option() is available only with openldap 2.x and netscape directory sdk.
+ if (function_exists('ldap_set_option')) {
+ foreach ($cpw_ldap_connect_opts as $opt => $value) {
+ // Make sure that constant is defined defore using it.
+ if (defined('LDAP_OPT_' . $opt)) {
+ // ldap_set_option() should not produce E_NOTICE or E_ALL errors and does not modify ldap_error().
+ // leave it without @ in order to see any weird errors
+ if (! ldap_set_option($cpw_ldap_con,constant('LDAP_OPT_' . $opt),$value)) {
+ // set error message
+ array_push($msgs,sprintf(_("Setting of LDAP connection option %s to value %s failed."),$opt,$value));
+ $cpw_ldap_con_err=true;
+ }
+ } else {
+ array_push($msgs,sprintf(_("Incorrect LDAP connection option: %s"),$opt));
+ $cpw_ldap_con_err=true;
+ }