chewie Posted September 30, 2009 Share Posted September 30, 2009 <?php $dn = "OU=SBSUsers,OU=Users,OU=MyBusiness,DC=contoso,DC=local"; $attributes = array("displayname", "aim", "msn", "yahoo", "skype"); $filter = "(cn=*)"; $ad = ldap_connect("ldap://ats.local") or die("Couldn't connect to AD!"); ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3); $bd = ldap_bind($ad,"Administrator@contoso.local","password") or die("Couldn't bind to AD!"); $result = ldap_search($ad, $dn, $filter, $attributes); $entries = ldap_get_entries($ad, $result); echo "<center>"; echo "<table border=1 bgcolor='#000000' cellpadding=10 cellspacing=10><tr bgcolor='#FFFFFF'><th>User</th><th><img src='/images/aim.png' height=25 width=25></th><th><img src='/images/msn.jpg' height=25 width=25></th><th><img src='/images/yahoo.gif' height=25 width=25></th><th><img src='/images/skype.jpg' height=25 width=25></th></tr>"; for ($i=0; $i<$entries["count"]; $i++) { if ($entries[$i]["aim"]!=null || $entries[$i]["msn"]!=null || $entries[$i]["yahoo"]!=null || $entries[$i]["skype"]!=null ) { echo "<tr bgcolor='#FFFFFF'><td >"; echo $entries[$i]["displayname"][0]."</td><td>"; echo "<a href='aim:addbuddy?screenname=".$entries[$i]["aim"][0]."'>".$entries[$i]["aim"][0]."</a></td><td>"; echo "<a href='msnim:add?contact=".$entries[$i]["msn"][0]."'>".$entries[$i]["msn"][0]."</a></td><td>"; echo "<a href='ymsgr:addfriend?".$entries[$i]["yahoo"][0]."'>".$entries[$i]["yahoo"][0]."</a></td><td>"; echo "<a href='skype:".$entries[$i]["yahoo"][0]."?add'>".$entries[$i]["skype"][0]."</a></td></tr>"; } } echo "</table>"; echo "</center>"; ldap_unbind($ad); ?> My above code currently hits AD, and pulls out some custom information I've added for getting IM info for users that have it entered in. What I'd like to additionally do is query the users further, and only display those that are, lets say either in the security group Engineering, or the distrobution group IT. I've tried a # of ways to do this but keep going in circles and getting lost and not sure how to add that layer to my existing code. I'm sure I'm missing something simple, but can't figure out what! Quote Link to comment https://forums.phpfreaks.com/topic/176107-php-ad-cherry-picking-users-from-a-specific-group-from-a-list/ 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.