Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

397
Vistas
Get result count=0 when query email of an user by ldap_search

I need to write a script to get some user info in an LDAP server. This works well if I dont filter anything, but if I set filter to some specific user, the result always 0. I suspect the filter string, but not sure about that.

Here is the code:

<?php

// using ldap bind
$ldaprdn  = 'uid=riemann,dc=example,dc=com';     // ldap rdn or dn
$ldappass = 'password';  // associated password

// connect to ldap server
$ldapconn = ldap_connect("ldap.forumsys.com")
    or die("Could not connect to LDAP server.");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);


if ($ldapconn) {

    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

    // verify binding
    if ($ldapbind) {
        echo "LDAP bind successful...";
    } else {
        echo "LDAP bind failed...";
    }

}

$attributes = array('mail');
$accountname = "*"; //fine if =*, 0 if set it = riemann
$filter_person = "(&(sAMAccountName={$accountname}))";
echo $filter_person;
$search = ldap_search($ldapconn,"DC=example,DC=com", $filter_person, $attributes);
$data = ldap_get_entries($ldapconn, $search);
print_r($data);
?>
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I figured it out. It's my fault that I set $filter_person wrong.

It should be:

$filter_person = "uid={$accountname}";
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda