Page 1 of 1

Need help LDAP Bind show warning message

Posted: Thu Mar 31, 2016 10:45 am
by Tin
Hi everyone.

Today, we found some issue with ldap_bind when the user input the wrong password showing the message below.

[text]Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in C:\xampp\htdocs\auth.php on line 60[/text]

but when user input the right password not found any issue.
please advise me to fix the issue, I need to hide the warning message and show other message.

I am a newbie with PHP language. :)

Code: Select all

$username = $_POST['username'];
$password = $_POST['password'];
function ldap_authenticate($ldapserver, $domain, $username, $password) {
	if ($username != "" && $password != "") {
		putenv('LDAPTLS_REQCERT=never'); 
        $ds = @ldap_connect($ldapserver) or die('Could not connect to LDAP server.');
		$lb = ldap_bind($ds,$username.'@'.$domain,$password);
		if($lb) {
			return 1;
		} else {
			return NULL;
		}
    }
    return NULL;
}

Re: Need help LDAP Bind show warning message

Posted: Thu Mar 31, 2016 10:31 pm
by Christopher
You are suppressing error messages on the wrong line. Do:

Code: Select all

                $ds = ldap_connect($ldapserver) or die('Could not connect to LDAP server.');
                $lb = @ldap_bind($ds,$username.'@'.$domain,$password);
Better would be to convert the error into an Exception using set_error_handler().

Re: Need help LDAP Bind show warning message

Posted: Fri Apr 01, 2016 8:51 am
by Tin
Christopher wrote:You are suppressing error messages on the wrong line. Do:

Code: Select all

                $ds = ldap_connect($ldapserver) or die('Could not connect to LDAP server.');
                $lb = @ldap_bind($ds,$username.'@'.$domain,$password);
Better would be to convert the error into an Exception using set_error_handler().
Hi Christopher,

Thanks for your help.

I've solve my problem according to your assistance. :)