I am running apache2 and php5 in my windows PC.
I have protected my directory using .htaccess and.htpasswd. If login information is not set
You can use http authentication in PHP in addition to Apache (via .htaccess). This might give you more control.
From the manual:
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
// do the redirect here?
}