I need to use realm authentication on a folder on a PHP site running on a Windows IIS 7.5 web server. I have the following code below that works great on any .php
file within that directory.
The problem is I need to password protect access to the entire directory, including PDF, image files, css files etc. I can't place PHP code on those types of files.
I did have the IIS rewrite module installed on the server so I am assuming I can somehow add a rewrite in my web.config that can force all files through some sort of pass-through/handler PHP file.
I just have no idea how to do this.
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="Jonas Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'User pressed Cancel';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as you password.</p>";
}
?>