Password protect your directory without .htaccess
.htaccess is generally used for basic authentication of a folder/website. The data of users logging in using .htaccess is not stored or kept. It works untill the user’s browser remembers the credentials. And it would really be very difficult to keep track of users logging in using this method.
So, here is a very simple way of doing the same using HTTP authentication:
<?php
$myusername = “amanjain.com”;
$mypassword = “amanjain”;
/*The authentication technique can be different like using database or a key value pair file*/
if ($_SERVER["PHP_AUTH_USER"] == “” || $_SERVER["PHP_AUTH_PW"] == “” ||$_SERVER["PHP_AUTH_USER"] != $myusername || $_SERVER["PHP_AUTH_PW"] != $mypassword)
{
header(“HTTP/1.0 401 Unauthorized”);
header(“WWW-Authenticate: Basic realm=\”This is my protected area\”"); /*Replace ”This is my protected area” with your personal message*/
echo “<h1>Authorization Required For Accessing Content.</h1>”;/*If user cancels the authentication*/
die();
}
?>
That’s it. Simple right?

