简体   繁体   English

.htaccess DENY FROM ALL帮助?

[英].htaccess DENY FROM ALL help?

I have a photo sharing website that the user can edit their picture privacy. 我有一个照片共享网站,用户可以编辑他们的图片隐私。 One major concerns is that other users can see the pictures from the user that have been concidered hidden. 一个主要问题是其他用户可以看到来自用户的已被隐藏的图片。 So I though in my IMAGES directory, just put deny from all in a .htaccess file. 所以我虽然在我的IMAGES目录中,只是在.htaccess文件中放入deny from all

But that restricted all images from being displayed to. 但这限制了所有图像的显示。

What's the best way to do this? 最好的方法是什么?

Thanks 谢谢
Coulton 库尔顿

You could use mod rewrite and a dispatcher that retrieves the file of the url. 您可以使用mod rewrite和一个检索url文件的调度程序。 The dispatcher would also check credentials. 调度员还会检查凭据。

Example: user accesses http://mysite.com/getimage/123 示例:用户访问http://mysite.com/getimage/123

Configure mod rewrite to transform this into http://mysite.com/index.php?page=getimage&att=123 . 配置mod重写以将其转换为http://mysite.com/index.php?page=getimage&att=123 Because of rewrite, no user will ever access anything else beside the index.php page unless you configure the rewrite module to do this. 由于重写,除非您配置重写模块执行此操作,否则任何用户都不会访问index.php页面旁边的任何其他内容。

index.php is the dispatcher and checks if the page really exists. index.php是调度程序,检查页面是否确实存在。 If it does, it calls the controller that handles getimage. 如果是,则调用处理getimage的控制器。 The controller getimage checks user credentials and if the user can get the file 123, it displays 123.jpg. 控制器getimage检查用户凭证,如果用户可以获取文件123,则显示123.jpg。

This is just one variant of multiple solutions. 这只是多种解决方案的一种变体。 It all depends on your site architecture. 这一切都取决于您的网站架构。

On webservers that only allow you to put all files below the document root and not outside of it for situations like this, a .htaccess file with a deny from all directive is often used to not allow http access to a special directory and it's subdirectories. 对于只允许您将所有文件放在文档根目录下而不是在其外部的Web服务器,在这种情况下,带有deny from all指令的.htaccess文件通常用于不允许http访问特殊目录及其子目录。

Doing some kind of obfuscation (directory names created with the help of MD5 or SHA1 etc. functions) is not recommended. 不建议进行某种混淆(使用MD5或SHA1等功能创建的目录名称)。

Deliver your images with the help of a PHP function that can do all the necessary permission checks you need in your case. 借助PHP函数提供图像,可以在您的案例中执行所需的所有必要权限检查。 One easy example how to actually return the file is found here: 这里有一个如何实际返回文件的简单示例:

Return the contents of an image in php file? 在php文件中返回图像的内容?

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

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