每次打开时,我都必须提示对文件进行身份验证。我已经尝试过使用PHP身份验证。
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
}但是,它并不是每次都要求。我们可以使用Htaccess或Htpasswd来实现吗?
敬请指教。
发布于 2014-01-24 20:05:45
您可以尝试使用.htaccess和.htpasswd
创建文件.htaccess put:
AuthType Basic
AuthName "restricted area"
AuthUserFile /opt/lampp/htdocs/test/.htpasswd # should be you file path & .htpasswd
require valid-user上面针对整个目录的解决方案。如果您希望使用单个文件,则在.htaccess中使用此选项
AuthType Basic
AuthName "demo.php" # name of the file for which you want authentication
AuthUserFile /opt/lampp/htdocs/test/.htpasswd #path of the folder
<Files "demo.php">
require valid-user
</Files>在.htpasswd中
test:do43GnYbHanDE #username test & pwd (download)您可以从here创建.htpasswd密码
https://stackoverflow.com/questions/21332077
复制相似问题