How can PHP be integrated with IIS to automatically authenticate users and retrieve their login names?

To integrate PHP with IIS for automatic user authentication and retrieval of login names, you can utilize Windows Authentication in IIS and access the user information through the $_SERVER superglobal in PHP. By enabling Windows Authentication in IIS, users will be automatically authenticated based on their Windows credentials, and their login names can be accessed in PHP using the $_SERVER['LOGON_USER'] variable.

<?php
if(isset($_SERVER['LOGON_USER'])){
    $loginName = $_SERVER['LOGON_USER'];
    echo "Welcome, $loginName!";
} else {
    echo "User authentication failed.";
}
?>