[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Using PHP LDAP functions: problem with filters

Posted on 2006-04-07
Medium Priority
Last Modified: 2008-02-26
I'm using php's ldap functions to authenticate users against an Open LDAP directory.

This filter: $filter = "cn=" .$userid.;
works fine - ($userid) comes via POST from a form.

So does this: $filter = "(&(|(cn=ISS*)(cn=ITS*))(cn=" .$userid."))";

So I'm pretty confident I can combine (AND/OR) arguments to the filter, and hard-code different forms of 'acceptable' usernames.

However, I want to limit the search to specific OU's. I'm trying to do this inside the filter, but as soon as I do even this:
$filter = "(&(ou=*)(cn=" .$userid."))";

it breaks. Am I trying to set 'acceptable' ou's in the wrong place, or something?

How do I specify acceptable containers?

Question by:mark_l_sanders

Accepted Solution

LinuxNubb earned 500 total points
ID: 16402845
I've never tried to filter using ou's.  I usually specify what container to look in when I run the ldap_search.

$sr=ldap_search($ds, "ou=container,o=company", $search_string );


Expert Comment

ID: 16408048
LDAP queries work based on object attributes, and while an object may be under an ou, it's not likely to have that ou as an attribute. Instead, do as LinuxNubb suggests and set the desired ou as a base DN for your search.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question