Scenario
I got this script at SOen :
$user = 'usuario';
$pass = '123';
$server = '192.168.0.1';
$domain = '@meudom';
$port = 389;
$ldap_connection = ldap_connect($server, $port);
if (!$ldap_connection) {
exit('Falha na conexão');
}
ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0);
$bind = @ldap_bind($ldap_connection, $username.$domain, $password);
if (!$bind) {
exit('Usuário e/ou senha incorreto(s)!');
}
echo 'Autenticado pelo LDAP';
ldap_close($ldap_connection);
Problem
The script works perfectly, but I like testing the dealings, and I found a problem.
If I incorrectly set $server
, in if (!$ldap_connection)
is passing anyway, instead of ending the script and printing the error ( exit('Falha na conexão')
).
Doubt
I would like to know the possible cause, and if there are other ways to validate the connection.