troubleshooting Question

PHP LDAP query to Active Directory

Avatar of AshcorTech
AshcorTech asked on
PHPActive DirectorySQL
3 Comments1 Solution2041 ViewsLast Modified:
Hello all,

Prior to this I've never had a need to interact with AD so I'm very new to it.

I have a website tool written in PHP5, running on a Linux Apache server.  This site had it's own login functionality and I've recently replaced that with querying the Active Directory domain for authentication using LDAP (borrowing from code examples found online).

this works fine.

Step 2) limiting access to only users in a certain AD security group however, is proving difficult.  The problem I'm having is constructing the AD query sting to use.  

If I look on the Windows Srv 2008 domain controller in the Active Directory Users and Computers tool I can find the group in this tree...

xxx.yyy.com > Organizational Units > CompanyName > groups and distribution lists > Security Groups > Support

So my question is, how do write the PHP LDAP query string to search that security group for a specific username.  

so for instance if the user login is "bsmith" I want so search that security group for any object with CN=bsmith I believe.

so I believe, to get a list of all users in that group, the query should look something like:

$query="(memberOf=OU=CompanyName,CN=Support,DC=xxx,DC=yyy,DC=com)";
$ldap_dn="OU=CompanyName,DC=xxx,DC=yyy,DC=com";

$results = ldap_search($ldap,$ldap_dn,$query);
if(!$results)echo "ERROR: ".ldap_error($ldap)."<BR>";

returns:

"Error: No such object"

any help with this would be much appreciated!

thanks.
ASKER CERTIFIED SOLUTION
Joseph Daly

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros