I wrote following code to get AD attributes using php
$base_dn = 'OU=User_Accounts,DC=test,DC=local';
$filter = "(givenname=*$accountName*)";
$attributes = array();
$attributes[] = 'samaccountname';
$attributes[] = 'givenname';
$attributes[] = 'sn';
$attributes[] = 'userAccountControl';
$attributes[] = 'ProtectedFromAccidentalDeletion';
$result = ldap_search($ldap_connection, $base_dn, $filter, $attributes);
$entries = ldap_get_entries($ldap_connection, $result);
for ($x=0; $x<$entries['count']; $x++){
$jsonArray[$x]['samaccountname'] = $entries[$x]["samaccountname"][0];
$jsonArray[$x]['givenname'] = $entries[$x]["givenname"][0];
$jsonArray[$x]['surname'] = $entries[$x]["sn"][0];
$jsonArray[$x]['isenabled'] = $entries[$x]["userAccountControl"][0];
$jsonArray[$x]['ProtectedFromAccidentalDeletion'] = $entries[$x]["ProtectedFromAccidentalDeletion"][0];
}
Using above code, I can get the user's samaccountname
, givenname
and surname
, but userAccountControl
and ProtectedFromAccidentalDeletion
are returning null values.
Can someone please advise how I can get those values?
Thanks in advance.