Jump to content

ldap_get_entries issue


synking
Go to solution Solved by synking,

Recommended Posts

Hey guys,

 

 i am having trouble searching our ldap server and getting results from it.

 1 <?php
  2
  3 $serv = 'ransohoff.com';
  4
  5 $user = 'jking@ransohoff.com';
  6
  7 $pass = 'V@lolon1';
  8
  9 $tree = "OU=Ransohoff Users,DC=ransohoff,DC=com";
 10
 11 $filter = '(&(objectClass=user)(objectCategory=person))';
 12
 13 //$attrib = array("samaccountname","telephonenumber","othertelephone");
 14
 15
 16 $ADconn = ldap_connect($serv);
 17
 18 ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
 19 ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search.
 20
 21 if($ADconn) {
 22
 23     $ADbind = ldap_bind($ADconn, $user, $pass);
 24     if(!$ADbind) die("Unable to bind to connection " .ldap_error($ADconn)." ".ldap_errno($ADconn)."  <br>");
 25
 26 } else {
 27
 28     echo ("Unable to connect to AD server");
 29 }
 30
 31 print('Ldap = '.$ADconn.', Ldap_dn = '.$tree.', Query = '.$filter);
 32
 33 $search = ldap_search($ADconn, $tree, $filter) or die ("Error in search query: ".ldap_error($ADconn));
 34
 35 if($search) {
 36
 37     for($i=0;$i<count($search);$i++){
 38         print_r(ldap_get_entries($ADconn,$search[$i]));
 39         print "\n";
 40     }
 41 } else {
 42
 43    print(ldap_error($ADconn). " ".ldap_errno($ADconn));
 44
 45 }
 46 ldap_close($ADconn);
 47 ?>

I have searched both here and google to try and solve the issue, but to me everything looks right and should be listing the user information.  Im not exactly sure where my problem is but i keep getting this warning and im not sure how to solve it

PHP Warning:  ldap_get_entries() expects parameter 2 to be resource, null given in /var/www/html/ldap/PhoneList.php on line 38

 

 

Im not exactly sure what im doing wrong.
Link to comment
Share on other sites

  • Solution

My for loop must have been clearing results while it was running.. i had to modify it so that the ldap_get_entries happens outside of the for loop.

if($search) {
     $entries = (ldap_get_entries($ADconn,$search));
     for($i=0;$i<$entries["count"];$i++){
         print("<pre>");
         print("User: " .$entries[$i]["cn"][0]." <br />");
         print("Email: ".$entries[$i]["mail"][0]." <br />");
         print("Telephone: ".$entries[$i]["telephone"][0]." <br />");
        #print_r($entries);
        print "\n";
         print("</pre>");

Now it all works fine.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.