如何使用 apache 或 .htaccess 限制对某种内容的访问?
我正在建立一个网站,用户可以在其中上传照片,并且可以将它们标记为私有,这样就没有人可以看到它们。
我知道如何在 php 中使用基于 ACL 的系统,但如果任何人有图像文件的直接链接,他们仍然可以访问这些照片。
例如:用户 1 想与用户 2 共享照片 A,因此授予他访问权限。用户 2 右键单击图像,然后复制其 url,例如“http://example.com/private123.jpeg”,并将其发送给用户 3。现在用户 3 可以看到他不应该看到的图像。
总而言之,我需要一种基于用户权限来保护图像的方法,但仍然让它们加载速度快如闪电(因此每次请求图像时运行 php 脚本都会被丢弃)。
用apache可以吗?我在想也许我可以在用户登录时设置一个 cookie,并让 apache 以某种方式检查它。我不在乎 cookie 是否可以伪造,99,99+% 的用户不会知道如何做到这一点,而且照片不需要比这更多的安全性。
I'm building a site in which users can upload photos, and they can mark them as private, so no one can see them.
I know how to use an ACL-based system in php, but anyone will still be able to access the photos if they have the direct link to the image file.
Eg: User 1 wants to share Photo A with User 2, so he grants him access. User 2 right clicks on the image, and copies its url, eg 'http://example.com/private123.jpeg', and sends it to User 3. Now user 3 can see the image he shouldn't be able to see.
To sum up, I need a way to protect images based on user permissions, but still have them loading lightning fast (so running a php script each time an image is requested, is discarded).
Is it possible with apache? I was thinking that maybe I could set up a cookie when the user logs in, and let apache check that somehow. I don't care if cookies can be faked, 99,99+% of the users won't know how to do that, and the photos don't need more security than that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将所有图像保存在自己的目录中,并在该目录中放置一个包含此内容的 .htaccess 文件
Keep all the images in their own directory, and in that directory, put a .htaccess file with this in it