PHP keeping Names after breaking urls into a multidimensional array - php

If you downvote my question, please be KIND enough to leave a reason
Hey guys I got a little snip that will take a structure of urls like so
// brevity
[182] => Array
(
[path] => /home-phone/troubleshooting
[name] => Troubleshooting
)
[183] => Array
(
[path] => /home-phone/troubleshooting/my-voicemail-to-e-mail-feature-is-not-working
[name] => My Voicemail to E-mail feature is not working.
)
[184] => Array
(
[path] => /home-phone/troubleshooting/when-i-receive-my-voicemail-by-e-mail-i-cannot-hear-the-message
[name] => When I receive my voicemail by e-mail, I cannot hear the message.
)
[185] => Array
(
[path] => /home-phone/troubleshooting/i-don-t-hear-a-dial-tone-when-i-pick-up-my-phone
[name] => I don't hear a dial tone when I pick up my phone.
)
[186] => Array
(
[path] => /home-phone/troubleshooting/i-moved-my-voice-adapter-and-can-no-longer-make-or-receive-calls
[name] => I moved my Voice adapter and can no longer make or receive calls.
)
[187] => Array
(
[path] => /home-phone/troubleshooting/my-call-waiting-is-not-working-since-i-forwarded-voice-to-another-line
[name] => My call waiting is not working since I forwarded Voice to another line.
)
[188] => Array
(
[path] => /home-phone/troubleshooting/i-m-unable-to-complete-transactions-on-ivr-phone-calls-like-online-banking
[name] => I'm unable to complete transactions on IVR phone calls (like online banking).
)
[189] => Array
(
[path] => /home-phone/troubleshooting/i-can-t-get-a-dial-tone-and-i-could-before
[name] => I can't get a dial tone (and I could before).
)
[190] => Array
(
[path] => /home-phone/troubleshooting/im-not-getting-my-voicemail-to-e-mail-messages
[name] => I'm not getting my Voicemail to E-mail messages.
)
[191] => Array
(
[path] => /home-phone/troubleshooting/my-caller-id-has-not-worked-since-i-forwarded-my-voice-line-to-another-phone-line
[name] => My Caller ID has not worked since I forwarded my Voice line to another phone line.
)
[192] => Array
(
[path] => /home-phone/troubleshooting/im-having-trouble-sending-andor-receiving-a-fax
[name] => I'm having trouble sending and/or receiving a FAX.
)
// brevity
And turn them into a multidim array, like this
[4] => home-phone
[home-phone] => Array
(
// brevity
[9] => troubleshooting
[troubleshooting] => Array
(
[0] => my-voicemail-to-e-mail-feature-is-not-working
[1] => when-i-receive-my-voicemail-by-e-mail-i-cannot-hear-the-message
[2] => i-don-t-hear-a-dial-tone-when-i-pick-up-my-phone
[3] => i-moved-my-voice-adapter-and-can-no-longer-make-or-receive-calls
[4] => my-call-waiting-is-not-working-since-i-forwarded-voice-to-another-line
[5] => i-m-unable-to-complete-transactions-on-ivr-phone-calls-like-online-banking
[6] => i-can-t-get-a-dial-tone-and-i-could-before
[7] => im-not-getting-my-voicemail-to-e-mail-messages
[8] => my-caller-id-has-not-worked-since-i-forwarded-my-voice-line-to-another-phone-line
[9] => im-having-trouble-sending-andor-receiving-a-fax
)
// brevity
)
Works pretty good, but I got to the end and realized I'd lost all my Names
(your can see theirs a second column for names), I left a spacer for a Name,
but for the life of me can't figure out how to get it in there now =(
Any ideas?
EDIT forgot my source code ;)
$tree = array();
foreach($indexArray as $branch) {
$limb = explode('/', $branch['path']);
$subTree = array(array_pop($limb));
foreach (array_reverse($limb) as $dir) {
$subTree = array($dir => $subTree);
}
$tree = array_merge_recursive($tree, $subTree);
}
Expected output should be
[Home Phone] => home-phone
[home-phone] => Array
(
// brevity
[Troubleshooting] => troubleshooting
[troubleshooting] => Array
(
[My Voicemail to E-mail feature is not working.] => my-voicemail-to-e-mail-feature-is-not-working
[When I receive my voicemail by e-mail, I cannot hear the message.] => when-i-receive-my-voicemail-by-e-mail-i-cannot-hear-the-message
[I don't hear a dial tone when I pick up my phone.] => i-don-t-hear-a-dial-tone-when-i-pick-up-my-phone
// etc
)
// brevity
)

Since you did not put expected output am working on assumption .. you can try :
$data = array();
$i = 0 ;
foreach ( $array as $key => $value ) {
$temp = array();
setPath($temp,dirname($value['path']) . "/$i/path", basename($value['path']));
setPath($temp, dirname($value['path']) . "/$i/name", $value['name']);
$data = array_merge_recursive($data, $temp);
$i ++;
}
echo "<pre>";
print_r($data);
Output
Array
(
[home-phone] => Array
(
[path] => troubleshooting
[name] => Troubleshooting
[troubleshooting] => Array
(
[1] => Array
(
[path] => my-voicemail-to-e-mail-feature-is-not-working
[name] => My Voicemail to E-mail feature is not working.
)
[2] => Array
(
[path] => when-i-receive-my-voicemail-by-e-mail-i-cannot-hear-the-message
[name] => When I receive my voicemail by e-mail, I cannot hear the message.
)
[3] => Array
(
[path] => i-don-t-hear-a-dial-tone-when-i-pick-up-my-phone
[name] => I don't hear a dial tone when I pick up my phone.
)
[4] => Array
(
[path] => i-moved-my-voice-adapter-and-can-no-longer-make-or-receive-calls
[name] => I moved my Voice adapter and can no longer make or receive calls.
)
[5] => Array
(
[path] => my-call-waiting-is-not-working-since-i-forwarded-voice-to-another-line
[name] => My call waiting is not working since I forwarded Voice to another line.
)
[6] => Array
(
[path] => i-m-unable-to-complete-transactions-on-ivr-phone-calls-like-online-banking
[name] => I'm unable to complete transactions on IVR phone calls (like online banking).
)
[7] => Array
(
[path] => i-can-t-get-a-dial-tone-and-i-could-before
[name] => I can't get a dial tone (and I could before).
)
[8] => Array
(
[path] => im-not-getting-my-voicemail-to-e-mail-messages
[name] => I'm not getting my Voicemail to E-mail messages.
)
[9] => Array
(
[path] => my-caller-id-has-not-worked-since-i-forwarded-my-voice-line-to-another-phone-line
[name] => My Caller ID has not worked since I forwarded my Voice line to another phone line.
)
[10] => Array
(
[path] => im-having-trouble-sending-andor-receiving-a-fax
[name] => I'm having trouble sending and/or receiving a FAX.
)
)
)
)
Function Used
function setPath(&$temp, $url, $value) {
foreach ( array_filter(explode("/", $url)) as $key ) {
$temp = &$temp[$key];
}
$temp = $value;
}

Related

Getting out the value of a key in multidimentional array in php

In my php query I got this output:
{"projects":[{"id":127,"name":"efrat","status":{"id":10,"name":"development","label":"development"},"description":"","enabled":true,"view_state":{"id":10,"name":"public","label":"public"},"access_level":{"id":90,"name":"administrator","label":"administrator"},"custom_fields":[{"id":1,"name":"Customer email","type":"email","default_value":"","possible_values":"","valid_regexp":"","length_min":0,"length_max":50,"access_level_r":{"id":10,"name":"viewer","label":"viewer"},"access_level_rw":{"id":10,"name":"viewer","label":"viewer"},"display_report":true,"display_update":true,"display_resolved":true,"display_closed":true,"require_report":false,"require_update":false,"require_resolved":false,"require_closed":false}],"versions":[],"categories":[{"id":93,"name":"Monitor","project":{"id":0,"name":null}},{"id":31,"name":"Proactive","project":{"id":0,"name":null}},{"id":30,"name":"Project","project":{"id":0,"name":null}},{"id":29,"name":"Support","project":{"id":0,"name":null}}]}]}
after using 'json_decode' method on it, I get this:
"(
[projects] => Array
(
[0] => Array
(
[id] => 127
[name] => myprojectname
[status] => Array
(
[id] => 10
[name] => development
[label] => development
)
[description] =>
[enabled] => 1
[view_state] => Array
(
[id] => 10
[name] => public
[label] => public
)
[access_level] => Array
(
[id] => 90
[name] => administrator
[label] => administrator
)
[custom_fields] => Array
(
[0] => Array
(
[id] => 1
[name] => Customer email
[type] => email
[default_value] =>
[possible_values] =>
[valid_regexp] =>
[length_min] => 0
[length_max] => 50
[access_level_r] => Array
(
[id] => 10
[name] => viewer
[label] => viewer
)
[access_level_rw] => Array
(
[id] => 10
[name] => viewer
[label] => viewer
)
[display_report] => 1
[display_update] => 1
[display_resolved] => 1
[display_closed] => 1
[require_report] =>
[require_update] =>
[require_resolved] =>
[require_closed] =>
)
)
[versions] => Array
(
)
[categories] => Array
(
[0] => Array
(
[id] => 93
[name] => Monitor
[project] => Array
(
[id] => 0
[name] =>
)
)
[1] => Array
(
[id] => 31
[name] => Proactive
[project] => Array
(
[id] => 0
[name] =>
)
)
[2] => Array
(
[id] => 30
[name] => Project
[project] => Array
(
[id] => 0
[name] =>
)
)
[3] => Array
(
[id] => 29
[name] => Support
[project] => Array
(
[id] => 0
[name] =>
)
)
)
)
)
)"
In my PHP, how can I release the "name" object value (the result should be 'myprojectname') from this array? I've tried many foreach loops that got me nowhere.
Thank you,
It looks like you have one object, that when decoded actually only has one array item. So, in your case, ‘myprojectname’ may simply be “$projects[0][‘name’]”
If many array items, you could
foreach ($projects as $project) {
echo $project[‘name’];
}
EDIT: I took object provided and json_decoded it myself, it doesn't match the json_decoded item presented by OP -- the first image shows the code to var_dump 'name' OP desired, part of the code also below:
$decoded = json_decode($obj);
$projects = $decoded->projects;
$name = $projects[0]->name;
Your 'projects' contains an array ("projects":[{"id":127, ... }]). I assume that the 'projects'-array might contain multiple 'project'-objects like this?
{
"projects":
[
{
"id":127,
"name":"my-project"
},
{
"id":128,
"name":"my-other-project"
}
]
}
In that case you need the arrow notation to access the name property, for example:
foreach ($projects as $project_object) {
foreach ($project_object as $project) {
echo $project->name . '<br/>';
}
}
EDIT:
I took a minimal code example of the OP and got the expected result:
Can you add more details in your code snippets in your original question or provide us with a working example of your code?
There are some online PHP sandboxes that can help you with this. For example: I stripped out all code that does not seem related to your question and got the result you are looking for in two different ways:
http://sandbox.onlinephpfunctions.com/code/009c53671fd9545e4fcecfe4b0328974381ee2ce
It is also a good idea to sum up all the foreach loops that you already tried, so we can see if you were nearly there with your own solution. This way we can understand your question better and it prevents us from offering solutions that you already used.

Array inside array, only take incoming array

I have the following array structure, this is the array passed in to $response
Array
(
[inbox] => Array
(
[0] => Array
(
[location] => 3
[ID] => 8ba84195fe79a89af1a4b5bd8c280621
[smsc_number] => +44******
[sent] => 2013-02-25 14:57:20
[coding] => Default GSM alphabet (no compression)
[remote_number] => +447****
[status] => Read
[body] => Yeppp
)
)
[outbox] => Array
(
[0] => Array
(
[location] => 2
[ID] => d22c4368fadd64e98fab64acb6b8fa34
[reference_number] => 1
[class] => 1
[coding] => Default GSM alphabet (no compression)
[remote_number] => *****
[status] => Sent
[body] => Test
)
[1] => Array
(
[location] => 0
[ID] => f0c05e8dd2578d16d73bf5dbcf2ec3e6
[class] => 1
[coding] => Default GSM alphabet (no compression)
[remote_number] => 0****
[status] => UnSent
[body] => fdgg ddfgfdg fd
)
[2] => Array
(
[location] => 1
[ID] => d7537acb1b3994ecc11369bac46c4bb6
[class] => 1
[coding] => Default GSM alphabet (no compression)
[remote_number] => 0****3
[status] => UnSent
[body] => fdgg ddfgfdg fd
)
)
)
I'm only interested in the body of the inbox array. I thought I could just do two loops to get this, or just do $response[0] but it doesn't seem to work. Heres what I have:
$response = $sms->Get();
foreach ($response[0] as $value) {
foreach ($response as $value1) {
echo($value1['body']);
}
}
I'm obviously doing something very stupid - Any help would be really appreciated
Try this
foreach ($response['inbox'] as $inb) {
echo($inb['body']); }

getting story tags from graph api returns strange id results for the tagged

The best way for me to explain this is to show you. Seems like a float() error in a 64bit system.
when i call /anotherfeed/feed or any page for that matter, posts with story_tags return some of the id's as a float error.
sample story tag with float error in id. [id] => 1.7153566624E+14
My question is, how do i fix this, or what am i doing wrong? all i am doing is looping in a foreach statement.
if($fvalue[story_tags]){
echo 'Tags: ';
$sTags=$fvalue[story_tags];
foreach ($sTags as $skey=>$svalue){
foreach ($svalue as $gkey=>$hvalue){
$id=$hvalue[id];
echo ''.$hvalue[name].' '.$id.' ';
}
}
}
[story_tags] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 1.7153566624E+14
[name] => Another Feed
[offset] => 0
[length] => 12
[type] => page
)
)
Array
(
[data] => Array
(
[0] => Array
(
[id] => 171535666239724_156133294510726
[from] => Array
(
[name] => Another Feed
[category] => App page
[id] => 171535666239724
)
[story] => Another Feed shared Non-Profits on Facebook's photo.
[story_tags] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 1.7153566624E+14
[name] => Another Feed
[offset] => 0
[length] => 12
[type] => page
)
)
[20] => Array
(
[0] => Array
(
[id] => 41130665917
[name] => Non-Profits on Facebook
[offset] => 20
[length] => 23
[type] => page
)
)
)
[picture] => http://photos-d.ak.fbcdn.net/hphotos-ak-ash3/557037_10150932300320918_1908237167_s.jpg
[link] => http://www.facebook.com/photo.php?fbid=10150932300320918&set=a.85612830917.95996.41130665917&type=1
[name] => Wall Photos
[caption] => Have you heard of the #[159208207468539:274:One Day without Shoes] (ODWS) campaign? ODWS is an annual initiative by #[8416861761:274:TOMS] to bring awareness around the impact a pair of shoes can have on a child's life.
During the 2012 campaign, #[20531316728:274:Facebook] drove 20% of traffic to the ODWS microsite and TOMS even launched a Facebook-exclusive "Barefoot & Blue" giveaway with #[25266987484:274:Essie Nail Polish] for the second year in a row.
We think this is a pretty cool example of creating exclusive content around an important initiative that keeps people engaged and involved!
[properties] => Array
(
[0] => Array
(
[name] => By
[text] => Non-Profits on Facebook
[href] => http://www.facebook.com/nonprofits
)
)
[icon] => http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif
[type] => photo
[object_id] => 10150932300320918
[application] => Array
(
[name] => Photos
[id] => 2305272732
)
[created_time] => 2012-07-02T17:57:23+0000
[updated_time] => 2012-07-02T17:57:23+0000
[comments] => Array
(
[count] => 0
)
)
solution:
cURL - had to use number format with PHP_EOL to solve in cURL.
// $locs = curl call to graph api for /anotherfeed/feed, still need solution for foreach.
$locs=json_decode($returned, true);
$stId=number_format($locs[data][1][story_tags][0][0][id], 0, '', '').PHP_EOL;
echo $stId;
PHP-SDK
solution is same, long numbers in the foreach loop need to be ran through number_format.

Recursive function for a multidimensional array?

I am attempting to use a recursive function to search through a multidimensional array, such as the one below, to find certain values, i.e. people who went to certain school, majored in a certain subject, hold a certain job title, etc. In case your wondering, this array is output from the Facebook Graph API. In reality there are more than 3 offset arrays, depending on the number of friends a user has, it could be in the thousands.
Here's a solution I tried with very little knowledge of recursive functions (my first thought was to use in_array before I found out it didn't work for md arrays):
So to give you an idea of how the md array below works, check out this snippet of code:
$friend = $fqlResult[0]['name'];
echo "$friend";
*The output would be "BLANK" since I deleted the person's name.
$data = $fqlResult;
$collegemajor = (isset($value['education'][0]['concentration'][0]['name'])) ? $value['education'][0]['concentration'][0]['name'] : null ;
$major = "Business Administration";
if (isset($collegemajor)) {
foreach($data as $key=> $value) {
if ($value($collegemajor) == $major) {
echo "User $key is majoring in $major";
}
}
}
So here is the multidimensional array referenced above. In this example, I want to pull the names of all of the user's friends who majored in Business Admin. in college. As you can see from this snippet, there aren't any (I think) but in the long version of the array, there are plenty. The code above produces no output and I'm lost as to how to make it work. Any help would be greatly appreciated.
Array
(
[0] => Array
(
[name] => BLANK
[education] =>
[work] =>
)
[1] => Array
(
[name] => BLANK
[education] => Array
(
[0] => Array
(
[school] => Array
(
[id] => 108087985890571
[name] => St. Andrew's School
)
[year] => Array
(
[id] => 138383069535219
[name] => 2005
)
[type] => High School
)
[1] => Array
(
[school] => Array
(
[id] => 20697868961
[name] => Boston University
)
[concentration] => Array
(
[0] => Array
(
[id] => 108654845832522
[name] => Business Administration
)
)
[type] => College
)
[2] => Array
(
[school] => Array
(
[id] => 108289315859633
[name] => University of Miami
)
[year] => Array
(
[id] => 138879996141011
[name] => 2013
)
[type] => Graduate School
)
)
[work] => Array
(
)
)
[2] => Array
(
[name] => BLANK
[education] => Array
(
[0] => Array
(
[school] => Array
(
[id] => 115444241803885
[name] => Saint Andrews High School
)
[year] => Array
(
[id] => 137616982934053
[name] => 2006
)
[type] => High School
)
[1] => Array
(
[school] => Array
(
[id] => 112033702149888
[name] => Boca Raton High
)
[year] => Array
(
[id] => 137616982934053
[name] => 2006
)
[type] => High School
)
[2] => Array
(
[school] => Array
(
[id] => 108087985890571
[name] => St. Andrew's School
)
[type] => High School
)
[3] => Array
(
[school] => Array
(
[id] => 107573562605861
[name] => Duke University
)
[concentration] => Array
(
[0] => Array
(
[id] => 104045469631213
[name] => Political science
)
)
[type] => College
)
)
[work] =>
)
[4] => Array
(
[uid] => 1234567
[name] => BOB NO ONE
[education] => Array
(
[0] => Array
(
[school] => Array
(
[id] => 106039752760627
[name] => Berwick Academy
)
[year] => Array
(
[id] => 137616982934053
[name] => 2006
)
[type] => High School
)
[1] => Array
(
[school] => Array
(
[id] => 108087985890571
[name] => St. Andrew's School
)
[type] => High School
)
[2] => Array
(
[school] => Array
(
[id] => 105690226130720
[name] => Northeastern University
)
[concentration] => Array
(
[0] => Array
(
[id] => 108654845832522
[name] => Business Administration
)
)
[type] => College
[classes] => Array
(
[0] => Array
(
[id] => 189873264368867
[name] => 2011
)
)
)
)
There's really no need for recursion for something like this, considering the depth of the tree is always fixed and the structure is known. Using some nested loops would do the trick:
$friends = $fqlResult;
$friends_BA = array();
foreach ($friends as $friend) {
if (is_array($friend['education'])) {
foreach ($friend['education'] as $school) {
if (isset($school['concentration'])) {
foreach ($school['concentration'] as $concentration) {
if (strpos(strtolower($concentration['name']), 'business') !== false) {
$friends_BA[] = $friend;
continue 3; // skip to the next friend
}
}
}
}
}
}
var_dump($friends_BA);
You want a function that will find a specific value on a specific field in the array,
function arraySearch($key, $value, $array){
$flag = FALSE;
foreach($array as $result){
if(arraySearch($key, $value, $result)){
$flag = TRUE
}elseif(isset($result[$key] && $result[$key] == $value){
$flag = TRUE;
}
}
return $flag
}
to improve performance rather than setting $flag to true, you could return true as it will stop the execution of the function and prevent it from continuing to search the array.
Call it like so
foreach($fqlResult as $result){
if(arraySearch('concentration', 'Business Administration', $result)){
//You have found a user you are looking for, echo $result['name'] or do what you want with the result.
}
}

How to retrieve user info fra a Active Directory Security Group using LDAP and PHP

As you can see below I'm not getting any user info when I do a LDAP search to the security group. I want to use the $_SERVER[remote_user] to check if the user is a member of this group. I would also like to retrieve the info of this user and update the sql database with it. Is this possible?
$dn = "CN=Intra,OU=Common Security Groups,DC=mydomain,DC=local";
$filter = "(member=*)";
$ad = ldap_connect("IP") or die("Couldn't connect to AD!");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
$bd = ldap_bind( $ad, "username#mydomain.local", "password") or die("Can't bind to server.");
$sr = ldap_search($ad,$dn,$filter);
$entries = ldap_get_entries($ad, $sr);
print_r($entries);
Returns this:
Array
(
[count] => 1
[0] => Array
(
[objectclass] => Array
(
[count] => 2
[0] => top
[1] => group
)
[0] => objectclass
[cn] => Array
(
[count] => 1
[0] => Intra
)
[1] => cn
[description] => Array
(
[count] => 1
[0] => Group for (LDAP) INTRANET server access
)
[2] => description
[member] => Array
(
[count] => 4
[0] => CN=Fname1 Lname1,OU=Mail enabled users,OU=Aberdeen,DC=mydomain,DC=local
[1] => CN=Fname2 Lname2,OU=Mail enabled users,OU=Forres,DC=mydomain,DC=local
[2] => CN=Fname3 Lname3,OU=Houston,DC=mydomain,DC=local
[3] => CN=Fname4 Lname4,OU=Mail enabled users,OU=Bergen,DC=mydomain,DC=local
)
[3] => member
[distinguishedname] => Array
(
[count] => 1
[0] => CN=Intra,OU=Common Security Groups,DC=mydomain,DC=local
)
[4] => distinguishedname
[instancetype] => Array
(
[count] => 1
[0] => 4
)
[5] => instancetype
[whencreated] => Array
(
[count] => 1
[0] => 20100711172407.0Z
)
[6] => whencreated
[whenchanged] => Array
(
[count] => 1
[0] => 20100712063949.0Z
)
[7] => whenchanged
[usncreated] => Array
(
[count] => 1
[0] => 17491499
)
[8] => usncreated
[usnchanged] => Array
(
[count] => 1
[0] => 17498823
)
[9] => usnchanged
[name] => Array
(
[count] => 1
[0] => Intra
)
[10] => name
[objectguid] => Array
(
[count] => 1
[0] =>
)
[11] => objectguid
[objectsid] => Array
(
[count] => 1
[0] =>
)
[12] => objectsid
[samaccountname] => Array
(
[count] => 1
[0] => Intra
)
[13] => samaccountname
[samaccounttype] => Array
(
[count] => 1
[0] => 268435456
)
[14] => samaccounttype
[grouptype] => Array
(
[count] => 1
[0] => -2147483646
)
[15] => grouptype
[objectcategory] => Array
(
[count] => 1
[0] => CN=Group,CN=Schema,CN=Configuration,DC=mydomain,DC=local
)
[16] => objectcategory
[count] => 17
[dn] => CN=Intra,OU=Common Security Groups,DC=mydomain,DC=local
)
)
Everything worked fine when I used the normal DN:
$dn = "OU=Mail enabled users,OU=Bergen,DC=mydomain,DC=local";
But a AD expert told me this was a big NO-NO and that I should use Security Groups instead :\
Query the AD like this:
$dn = "DC=mydomain,DC=local";
$group_DN = "CN=Intra,OU=Common Security Groups,DC=mydomain,DC=local";
$filter = "(&(objectCategory=user)(memberOf=$group_DN))";
// ...
$sr = ldap_search($ad, $dn, $filter);
Have a look at the MSDN article about the LDAP search filter syntax for info on more complex filters.
Be sure to pay attention to the Special Characters section down on that page. A correct solution must pass $group_DN through an escaping mechanism before using it in the filter string!
Always try build filters as specific as possible. It is more efficient to let the LDAP server sort out records you don't want, instead of having more records transferred over the wire than you need and throw away half of them on the client.
Tomalak
I think the problem is that not all users in the Security Group comes from the same OU.
If I change
$dn = "DC=mydomain,DC=local";
to
$dn = "OU=Bergen,DC=mydomain,DC=local";
the filter works. But I also have 2 more OU's with users.

Categories