简体   繁体   English

限制访问网站上的图像

[英]Restricting access to images on a website

I'm putting together a portfolio website which includes a number of images, some of which I don't want to be viewable by the general public. 我正在整理一个投资组合网站,其中包括一些图像,其中一些我不希望公众可以看到。 I imagine that I'll email someone a user name and password, with which they can "log-in" to view my work. 我想我会通过电子邮件向某人发送用户名和密码,用户可以“登录”查看我的工作。

I've seen various solutions to the "hide-an-image" problem on line including the following, which uses php's readfile. 我已经看到了在线“隐藏图像”问题的各种解决方案,包括以下,它使用php的readfile。 I've also seen another that uses .htaccess. 我也见过另一个使用.htaccess的人。

Use php's readfile() or redirect to display a image file? 使用php的readfile()或重定向来显示图像文件?

I'm not crazy about the readfile solution, as it seems slow to load the images, and I'd like to be able to use Cabel Sasser's FancyZoom, which needs unfettered access to the image, (his library wants a link to the full sized image), so that rules out .htaccess. 我对readfile解决方案并不感到高兴,因为加载图像似乎很慢,我希望能够使用Cabel Sasser的FancyZoom,它需要不受限制地访问图像,(他的库需要一个完整的链接)大小的图像),以便排除.htaccess。

To recap what I'm trying to do: 重温我正在尝试做的事情:

1) Provide a site where I give users the ability to authenticate themselves as someone I'd like looking at my images. 1)提供一个网站,我让用户能够将自己认证为我想要查看我的图像的人。 2) Restrict random web users from being able see those images. 2)限制随机网络用户无法看到这些图像。 3) Use FancyZoom to blow up thumbnails. 3)使用FancyZoom炸掉缩略图。

I don't care what technology this ends up using -- Javascript, PHP, etc. -- whatever's cleanest and easiest. 我不关心最终使用什么技术--Javascript,PHP等 - 无论什么都是最干净和最简单的。

By the way, I'm a Java Developer, not a web developer, so I'm probably not thinking about the problem correctly. 顺便说一句,我是Java开发人员,而不是Web开发人员,所以我可能没有正确地考虑这个问题。

Instead of providing a link to an image. 而不是提供图像的链接。 Provide a link to a cgi script which will automatically provide the proper header and content of the image. 提供指向cgi脚本的链接,该脚本将自动提供图像的正确标题和内容。

For example: image.php?sample.jpg 例如:image.php?sample.jpg

You can then make sure they are already authenticated (eg pass a session id) as part of the link. 然后,您可以确保它们已经过身份验证(例如,传递会话ID)作为链接的一部分。

This would be part of the header, and then your image data can follow. 这将是标题的一部分,然后您的图像数据可以跟随。

header('Content-Type: image/jpeg');

Edit: If it has to be fast, you can write this in C/C++ instead of php. 编辑:如果必须快,你可以用C / C ++而不是php来编写。

使用.htaccess应该是最安全/最简单的方法,因为它内置于Web服务器本身的功能中。

I do not know if it fits your needs, but I solved a similar poblem(giving pictures to a restricted group of people) by using TinyWebGallery , which is a small gallery application without database. 我不知道这是否符合您的需要,但我通过使用解决了类似的poblem(给图片有限制的一群人) TinyWebGallery ,这是没有数据库中的小画廊的应用程序。

You can allow access to different directories via password and you can upload pictures directly into the filesystem, as TinyWebGallery will check for new dirs/pics on the fly. 您可以通过密码访问不同的目录,并且您可以将图片直接上传到文件系统,因为TinyWebGallery将动态检查新的目录/图片。 It will generate thumbnails and gives users possibility to rate / comment pictures (You can disable this). 它将生成缩略图并为用户提供评分/评论图片的可能性(您可以禁用此功能)。

This is not the smallest tool, however I thik it is far easier to setup than using apache directives and it looks better as naked images . 这不是最小的工具,但是我认为它比使用apache指令更容易设置,它看起来像裸图像更好。

如果您使用的是Nginx ,则可以使用Secure Link模块

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

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