Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

398
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!