在PHP / Apache的图像显示权限 [英] Image display permissions in PHP/Apache

查看:160
本文介绍了在PHP / Apache的图像显示权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP的网站有一个登录系统,并想使一个功能,只有特定的用户名可以查看特定的图像。我想,我想要做的是不是仅仅改变.htaccess文件更复杂,因为:a)这不会帮助那些/不允许查看图像用户之间的辨别,以及b)如果有人进入图片的准确网址(目录/图片/照片/ 230ru0q0238rn230nd_asdi0nqn8.jpg),他们仍然可以查看图像(因为它在目录中的物理文件,而不是文本在一个数据块,等等)。再次,通过限制的.htaccess将限制该目录作为一个整体,还是在它的所有文件,所以我无法弄清楚它是如何工作的。理想情况下,所有的图像会被试图直接通过其直接的URL访问这些被阻塞,图像只会之间的&LT出现; IMG> 标记如果用户的会话/用户名有效的,否则他们得到一个错误信息。

I have a PHP site with a login system, and am trying to make a feature where only specific usernames can view particular images. I think what I'm trying to do is more involved than merely changing the .htaccess file, because a) this won't help discern between users that are/aren't allowed to view the image, and b) if someone enters the exact URL of the image ("directory/images/photos/230ru0q0238rn230nd_asdi0nqn8.jpg") they can still view the image (since it's a physical file in the directory, and not text in a DB, etc.). Again, restricting via .htaccess would restrict the directory as a whole, or all files in it, so I can't figure out how it would work. Ideally, all images would be blocked by trying to access them directly through their direct URL, and the image would only appear between <img> tags if the user's session/username is valid, else they get an error message.

我听说过这个词,但ACL我不知道这与我想要做的。

I've heard the term ACL but I'm not sure this is related to what I'm trying to do.

推荐答案

授权和访问控制列表制度可以不同,但​​要完成你的问题的基本目标是:

The Authorization and ACL scheme can vary, but to accomplish the basic goal of your question:


  • 把图像PHP可以读取窗台一个非web访问的目录。

  • 使用的.htaccess 来重写一个脚本的所有请求(这可以消除preceding一步,假设它否认有任何直接访问文件)。

  • 确认请求用户可以查看所请求的图像。

  • 使用 ReadFile的()(或各种其他功能)输出图像。

  • Put the images in a non-web accessible directory that PHP can sill read.
  • Use .htaccess to rewrite all requests to a script (this may eliminate the preceding step, assuming it denies any direct access to the files).
  • Confirm that the requesting user can view the requested image.
  • Use readfile() (or a variety of other functions) to output the image.

这篇关于在PHP / Apache的图像显示权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆