限制访问网站上的图像 [英] Restricting access to images on a website

查看:91
本文介绍了限制访问网站上的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在组建一个投资组合网站,其中包含许多图像,其中一些我不希望被大众看到。我想我会通过电子邮件向用户发送用户名和密码,以便他们可以登录以查看我的工作。

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.

我已经看到了各种解决方案在线上的隐藏图像问题包括以下内容,该问题使用php的readfile。我还看到了另一个使用.htaccess的文件。

I've seen various solutions to the "hide-an-image" problem on line including the following, which uses php's readfile. I've also seen another that uses .htaccess.

使用php的readfile()还是重定向来显示图像文件?

我不是对于读取文件解决方案非常着迷,因为加载图像的速度似乎很慢,并且我希望能够使用Cabel Sasser的FancyZoom,该FancyZoom需要不受限制地访问图像(他的库需要链接到全尺寸图像),因此排除了.htaccess。

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.

回顾一下我想做的事情:

To recap what I'm trying to do:

1)提供一个让用户能够验证自己作为我想查看我的图像的人的站点。
2)限制随机Web用户查看那些图像。
3)使用FancyZoom放大缩略图。

1) Provide a site where I give users the ability to authenticate themselves as someone I'd like looking at my images. 2) Restrict random web users from being able see those images. 3) Use FancyZoom to blow up thumbnails.

我不在乎最终使用的是什么技术-Javascript,PHP等-不管是什么最干净,最简单。

I don't care what technology this ends up using -- Javascript, PHP, etc. -- whatever's cleanest and easiest.

顺便说一句,我是Java开发人员,而不是Web开发人员,所以我可能没有正确考虑问题。

By the way, I'm a Java Developer, not a web developer, so I'm probably not thinking about the problem correctly.

推荐答案

而不是提供图像链接。提供指向cgi脚本的链接,该链接将自动提供图像的正确标题和内容。

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.

例如:
image.php?sample.jpg

For example: image.php?sample.jpg

然后您可以确保它们已通过身份验证(例如,通过会话ID)作为链接的一部分。

You can then make sure they are already authenticated (e.g. pass a session id) as part of the link.

这将是标题的一部分,然后您的图像数据就可以跟随。

This would be part of the header, and then your image data can follow.

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

编辑:如果必须快速,则可以用C / C ++而不是php编写。

If it has to be fast, you can write this in C/C++ instead of php.

这篇关于限制访问网站上的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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