限制浏览器访问目录文件
在我的网站中,我想限制查看存储在名为“/content”的目录中的某些文件,这样只有登录的用户才能查看
现在的文件,任何输入 xxxxxxx.com/content/4dc32b1c0a630.png 的人都 可以查看这些文件进入浏览器可以看到这个图像文件
我已经将Options -Indexes添加到我的.htaccess文件中,但这没有做任何事情,
如果它有帮助的话我的网站是使用codeigniter构建的,所以PHP解决方案会很棒,不过我会接受你的任何建议!
谢谢你, 蒂姆
In my website, i want to restrict viewing certain files which are stored in a directory called "/content" such that only logged in users can view the files
as it stands right now anyone who types in xxxxxxx.com/content/4dc32b1c0a630.png into the browser can see this image file
I've added Options -Indexes to my .htaccess file but that didn't do anything
if it is helpful my site is built using codeigniter, so a PHP solution would be great, though I'd take any advice you might have!
thank you,
Tim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 mod_rewrite 将对
/content
中任何内容的访问重写为 PHP 脚本,该脚本将对用户进行身份验证,然后直接或通过 mod_xsendfile 提供文件。Use mod_rewrite to rewrite any accesses to anything in
/content
to a PHP script that will auth the user and then provide the file, either directly or via mod_xsendfile.将这些行放入您的根 .htacess 文件中,以阻止未经身份验证的用户访问
content/4dc32b1c0a630.png
:不过,我建议您使用通配符(如果可能)来匹配上面被阻止的文件,而不是列出每个文件以及每个单独的文件。
Put these lines in your root .htacess file to block access to
content/4dc32b1c0a630.png
for unauthenticated users:However I would suggest you use wild cards (if possible) to match blocked files above rather than listing each and every individual file.
您可以为此目的编写一个控制器。
在我的一个项目中,我仅为登录用户做了一个调整大小的图片控制器。它基于 timthumb 脚本 http://code.google.com/p/timthumb/
中控制器 __construct();编写用户验证代码即可!
因此,您将通过控制器调用这些文件,例如 http://www.site.com/images/1314 .png
You can write a controller for that purpose.
In one of my projects I've done a resized pictures controller only for logged in users. It's based on timthumb script http://code.google.com/p/timthumb/
In controller __contruct(); write user authentification code and that's all!
So you will call these files via controller, like http://www.site.com/images/1314.png