ldap_search com ldap_get_entries returns no value

Asked

Viewed 105 times

0

I’m making authentication via LDAP:

$server = '192.168.0.1';
$domain = '@meudom';
$port   = 389;
$auth_user  = 'usuario1';
$auth_pass  = '123';

$ldap_connection = ldap_connect($server, $port) or die('Erro na conexão');
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, $auth_user.$domain, $auth_pass);
if (!$bind) exit('Usuário e/ou senha incorreto(s)!');

$filter = "(uid={$auth_user})";
$result = ldap_search($ldap_connection, "(dc=meudom, dc=com)", $filter) or exit("Erro em search");
$entries = ldap_get_entries($ldap_connection, $result);

ldap_close($ldap_connection);

I’ve seen some examples in research, but all almost in a pattern.

Until the part of ldap_bind is authenticating perfectly.

What I would like, is to bring the user data, among other possible information, but in $filter, I have tested several ways:

  • "(uid={$auth_user})"
  • "(cn=*})"
  • "(or=*})"
  • etc.

Always the result of print_r($entries) is Array ( [count] => 0 ).


I don’t know if there’s really something wrong with the part about ldap_search or another place.

1 answer

1


removes the parentheses in search

ldap_search($ldap_connection, "dc=meudom, dc=com", $filter) –

  • It didn’t work. That’s right ldap_search($ldap_connection, "(dc=meudom, dc=com)", $filter)?

  • Yes, you can connect to the ldap server by another program ( ex Adexplorer ) to see the structure?

  • With you! I just tested.

  • remove parentheses in search ldap_search($ldap_connection, "dc=meudom, dc=com", $filter)

  • Dude I just tested this, I hadn’t seen your comment rs... But that’s right! Put in the answer I already confirm! Thank you!

  • I’ve already edited, confirm :D

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.