M4verick Posted December 31, 2009 Share Posted December 31, 2009 Hello all! I'm having an issue where I'm trying to query LDAP, however it's failing and returning - Warning: ldap_get_attributes() expects parameter 2 to be resource, array given in C:\wamp\www\ad.php on line 34. This is running on a WAMP server for use on an internal LAN on a Windows machine. Here's the code <?php $dn = "DC=ad,DC=fakedomain,DC=com"; if (isset($_POST['userid'])){ $userid = rtrim($_POST['userid']); } if (isset($_POST['criteria'])){ $cri = rtrim($_POST['criteria']); } $login = "username@ad.fakedomain.com"; $password = "password"; $ad = ldap_connect("ad.fakedomain.com") or die("Couldn't connect to AD!"); ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ad, LDAP_OPT_REFERRALS, 0); $bind = ldap_bind($ad,$login,$password); $filter = "($cri=$userid)"; $result = ldap_search($ad,$dn,$filter); echo $result."<br />"; $entry = ldap_get_entries($ad,$result); if (!isset($entry)){ echo "Your query has failed."; } else { echo $entry; $info = ldap_get_attributes($ad,$entry); for ($i=0; $i<$info["count"]; $i++) { $desc = ($info[$i]); $detail = ldap_get_values($ad,$entry,$desc); echo $info[$i]." </td><td align=left>"; for ($a=0; $a < $detail["count"]; $a++) { echo $detail[$a]; $b = $a + 1; } ;};}; ldap_unbind($ad); ?> Can anyone tell me why this is failing? I am a PHP newb, but definitely interested. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/186751-failing-to-query-ldap/ Share on other sites More sharing options...
Maq Posted December 31, 2009 Share Posted December 31, 2009 Warning: ldap_get_attributes() expects parameter 2 to be resource, array given in C:\wamp\www\ad.php on line 34. The second parameter you're giving ldap_get_attributes() is $entry. Now $entry is obviously an array returned by the method ldap_get_entries(). You need to change $entry to $result which is a resource returned by ldap_search(). Quote Link to comment https://forums.phpfreaks.com/topic/186751-failing-to-query-ldap/#findComment-986305 Share on other sites More sharing options...
M4verick Posted December 31, 2009 Author Share Posted December 31, 2009 Just to verify we're on the same page, is this what you're saying? Unfortunately I won't be in a position to check until tomorrow, but I am eager. I am slowly discovering the awesomeness that is PHP and you'll prolly be seeing me a bit more in the forums. $filter = "($cri=$userid)"; $entry = ldap_get_entries($ad,$filter); $result = ldap_search($ad,$dn,$entry); Quote Link to comment https://forums.phpfreaks.com/topic/186751-failing-to-query-ldap/#findComment-986327 Share on other sites More sharing options...
Maq Posted January 4, 2010 Share Posted January 4, 2010 No. Change: $info = ldap_get_attributes($ad,$entry); to this: $info = ldap_get_attributes($ad,$result); Quote Link to comment https://forums.phpfreaks.com/topic/186751-failing-to-query-ldap/#findComment-987934 Share on other sites More sharing options...
M4verick Posted January 4, 2010 Author Share Posted January 4, 2010 That results in - Warning: ldap_get_attributes(): supplied resource is not a valid ldap result entry resource in C:\wamp\www\ad.php on line 32 So, this error is telling me that it is not liking the returned query I'm assuming? Quote Link to comment https://forums.phpfreaks.com/topic/186751-failing-to-query-ldap/#findComment-988264 Share on other sites More sharing options...
zenlord Posted January 4, 2010 Share Posted January 4, 2010 I'm not sure about this, but I have been experimenting with PHP/LDAP the last two weeks and in the beginning I had some weird error messages because the connection and/or bind did not succeed. You might want to try to add 'or die()'-statements to your connection / bind-cmd's. Also: I had to set my ldap-options even before the connection was made (you set it between the connection and the bind)... HTH Quote Link to comment https://forums.phpfreaks.com/topic/186751-failing-to-query-ldap/#findComment-988314 Share on other sites More sharing options...
M4verick Posted January 4, 2010 Author Share Posted January 4, 2010 I tried your suggestions but it results in the same error. Quote Link to comment https://forums.phpfreaks.com/topic/186751-failing-to-query-ldap/#findComment-988393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.