简体   繁体   English

htpasswd用php变量保护页面

[英]htpasswd protect a page with php variables

I want anyone to be able to read 'file.php' but I want to password protect the same file if the url is 'file.php?page=mypage'. 我希望任何人都可以读取“ file.php”,但是如果URL为“ file.php?page = mypage”,则我想用密码保护同一文件。 I've tried htpasswd but it isn't working: 我已经尝试过htpasswd,但是没有用:

<FilesMatch "page.php?page=mypage">
AuthName "Secret page"
AuthType Basic
AuthUserFile /home/cowfart/public_html/.htpasswd
require valid-user
</FilesMatch>

What else could I do to make it work? 我还能做些什么来使其正常工作? By the way, this website is based around one file which gets variables from the url and echos other files depending on this variable 顺便说一下,这个网站是基于一个文件的,该文件从url获取变量,并根据此变量回显其他文件

I don't think it is possible to htpasswd files depending on their URL parameters. 我认为htpasswd文件取决于其URL参数是不可能的。 I think the best way to go about password protecting a page like this is to code a login script, requiring a user to login to access the page. 我认为,对这样的页面进行密码保护的最佳方法是编写一个登录脚本,要求用户登录才能访问该页面。

eg. 例如。

<?php
if($_GET['page'] == "mypage")){
 // Require login
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM