dongwei2983 2010-09-13 15:00
浏览 9

使用.htaccess保护文件

I have a set of files in a secure directory (currently secured by .htaccess, only 'the site' can access these files).

The files should only be available to members of the site; when they are logged in. I did have links in the members' area which went to a secure download script - however, using the readfile() function caused problems with the files across Browser/OS ie. losing line endings, corrupt PDFs.

So, I thought a better way might be to only allow people who have clicked the link (within the site) to access the files - hence they have to be logged in as a member. Going ditectly to the resource with it's URL would forward to a 403 forbidden page.

My .htaccess skills aren't the best, but I thought the concept would be similar to stopping hotlinking of images?

Any help - and knowing whether this is possible - would be greatly appreciated.

Best Regards,

Rich

  • 写回答

1条回答 默认 最新

  • douhan8892 2010-09-13 16:40
    关注

    What kind of login/authentication are you using? If you're using the regular HTTP auth stuff, you can just place those directives into the .htaccess along with

    Require valid-user
    

    which would allow access only to those who've succesfully logged in. If it's session based, you'll have to fix up the intermediary PHP script, as Apache knows nothing of PHP sessions. At most it can check for the presence/content of a cookie, but then you'd be trusting the clien to not mess with the cookie's conents.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号