What is the purpose of the $felder variable in the PHP code provided for reading Active Directory with LDAP?

The purpose of the $felder variable in the PHP code provided for reading Active Directory with LDAP is to specify the attributes that we want to retrieve from the Active Directory. By defining the attributes in the $felder variable, we can control which information is fetched from the LDAP server.

<?php
$ldapserver = 'ldap://your_ldap_server';
$ldapuser      = 'your_ldap_user';
$ldappass     = 'your_ldap_password';
$ldaptree    = "OU=Users,DC=example,DC=com";
$felder = array("samaccountname", "givenname", "sn", "mail");

$ldapconn = ldap_connect($ldapserver) or die("Could not connect to LDAP server.");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($ldapconn, $ldapuser, $ldappass) or die("Could not bind to LDAP server.");

$ldapsearch = ldap_search($ldapconn, $ldaptree, "(objectclass=person)", $felder);
$result = ldap_get_entries($ldapconn, $ldapsearch);

foreach($result as $user) {
    echo "Username: " . $user["samaccountname"][0] . "<br>";
    echo "First Name: " . $user["givenname"][0] . "<br>";
    echo "Last Name: " . $user["sn"][0] . "<br>";
    echo "Email: " . $user["mail"][0] . "<br>";
    echo "<br>";
}

ldap_close($ldapconn);
?>