Need help LDAP Bind show warning message

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tin
Forum Newbie
Posts: 4
Joined: Thu Mar 31, 2016 10:37 am

Need help LDAP Bind show warning message

Post 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;
}
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help LDAP Bind show warning message

Post 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().
(#10850)
Tin
Forum Newbie
Posts: 4
Joined: Thu Mar 31, 2016 10:37 am

Re: Need help LDAP Bind show warning message

Post 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. :)
Post Reply