douyi1963 2018-02-04 17:42 采纳率: 0%
浏览 69
已采纳

htpasswd用php变量保护页面

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'. I've tried htpasswd but it isn't working:

<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

  • 写回答

1条回答 默认 最新

  • doushi7819 2018-02-04 17:52
    关注

    I don't think it is possible to htpasswd files depending on their URL parameters. 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
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?