Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:56:10+00:00 2026-05-29T06:56:10+00:00

I’m trying to retrieve information(descriptionand Mail) from my active directory without knowing my DN

  • 0

I’m trying to retrieve information(descriptionand Mail) from my active directory without knowing my DN for all the users who have logged in on my application using their domain credentials, i’m only able to retrieve the information if i provide a dn of which each dn is very different for all the users cause of the departments and Organizational Units, the binding works fine the problem is only retrieving the data specified above.

My code is as follows..
NB:I’ve changed the values of some fields.

<?php
 ldap_authenticate();
 function ldap_authenticate() {

 //using ldap bind
 $ldaprdn  = 'username';//ldap rdn or dn
 $ldappass = 'password';// associated password
 $filter="(&(objectClass=user))";
 $justthese = array("sn","displayName");
 //connect to ldap server
 $ldapconn = ldap_connect("hostname.net");

 if ($ldapconn){
  //binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
  //verify binding
    if($ldapbind){
        $dn='CN=Donald Mailula,OU=Users,OU=Group Testing,OU=Central Office,DC=hostname,DC=net';
        $sr=ldap_read($ldapconn,$dn,$filter);
        $entry = ldap_get_entries($ldapconn, $sr);
        echo $entry[0]["mail"][0] . " is the email address of the cn your requested<br/>";
        echo $entry[0]["description"][0];
    }else{
       echo "LDAP bind failed...";
    }
  }
}

?>

My main problem is that i wont be able to know the dn of all the users who logged in so i need a way to search for record without the dn, or how to get the dn first and then search for the record i need.

Is it even possible guys?

Please help

Thanks
D

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:56:11+00:00Added an answer on May 29, 2026 at 6:56 am

    The thing you need is called ldap_search you can find a full sample here

    <?php
    // $ds is a valid connexion id (samAccountName)
    $dn = "o=Ma Compagnie, c=FR";
    $filter="(|(objectCategory=person)(samAccountName=$ds))";
    $justtheseattributes = array( "ou", "sn", "givenname", "mail");
    $sr=ldap_search($ds, $dn, $filter, $justtheseattributes);
    $info = ldap_get_entries($ds, $sr);
    echo $info["count"]." found entries.\n";
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.