Jump to content

ldap_get_entries issue


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

  Quote
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
https://forums.phpfreaks.com/topic/282569-ldap_get_entries-issue/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.