What is the purpose of displaying a thumbnailPhoto from Active Directory in PHP?

Displaying a thumbnailPhoto from Active Directory in PHP allows you to show a user's profile picture on a website or application. This can enhance user experience and personalize the user interface. To achieve this, you need to retrieve the thumbnailPhoto attribute from Active Directory and then display it on the webpage using PHP.

<?php
$ldap_dn = "ldap://your-ldap-server"; // LDAP server address
$ldap_user = "username"; // LDAP username
$ldap_pass = "password"; // LDAP password

$ldap = ldap_connect($ldap_dn);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);

if (ldap_bind($ldap, $ldap_user, $ldap_pass)) {
    $filter = "(sAMAccountName=username)"; // Filter to search for a specific user
    $result = ldap_search($ldap, "ou=Users,dc=example,dc=com", $filter);
    $entries = ldap_get_entries($ldap, $result);

    if ($entries['count'] > 0) {
        $photo = $entries[0]['thumbnailphoto'][0];
        header("Content-type: image/jpeg");
        echo $photo;
    } else {
        echo "User not found.";
    }
} else {
    echo "Unable to bind to LDAP server.";
}

ldap_close($ldap);
?>