且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

监控图像访问和/或阻止直接访问

更新时间:2023-12-01 15:13:46

没有子弹证明方式。但是,您可以使用启发式方法。检查以下标题:

There is not bullet proof way. However, you can use heuristics. Inspect the following headers:


  1. Referer - 此标题将出现是因为< img> 标签或CSS。如果直接请求图像(通过在地址栏中键入URL),此标题将为空。如果此标头包含另一个域,那么该其他网站热链接您的图像。 请注意,这是预期的行为,但不保证每个浏览器都会以这种方式运行。

  1. Referer -- this header will be present is the image was requested by the browser as a result of <img> tag or CSS. This header will be empty if the image was requested directly (by typing the URL in address bar). If this header contains another domain then that other website hot-linked your image. Note that this is the expected behavior but it is not guaranteed that every browser will behave this way.

接受 - 此标头将包含请求图片时,如 image / * 这样的字符串,因为浏览器发现它嵌入在HTML标签或CSS中。当有人通过在浏览器中输入来直接请求图像时,您会发现 text / html,application / xhtml + xml 等值。这是因为浏览器不知道什么时候它会要求 http://website.com/someimage.jpg ;因此它***要求 text / html 内容。

Accept -- this header will contain a string such as image/* when image was requested because browser found it embedded in HTML tags or CSS. When someone requests the image directly by typing in the browser, you'll find values such as text/html,application/xhtml+xml etc. This is because browser does not know what to expect when it requests http://website.com/someimage.jpg; hence it will preferably ask for text/html content.

在Apache中,您可以检查(和匹配)HTTP标头以确定内容是否可访问。我不确定其他平台,但你可以写一个通用的代理脚本来提供图像。

In Apache, you can check (and match) HTTP headers to determine whether content is accessible or not. I am not sure about other platforms, but you can write a generic proxy script for serving images.

如果图像URL显示您不想公开的信息,则可以使用哈希或加密对其进行模糊处理。因此,不要提供以下内容:

If the image URL reveals information that you do not want disclosed, you can obfuscate it by using hashes or encryption. So instead of serving content such as:

<img src="/images/users/12345.jpg">

你会写:

<img src="/images/users/image.php?hash=<?php echo md5('secret' . '12345'); ?>">

您需要编写一个脚本,将相应的图像发送到浏览器。

You'll need to write a script that sends the corresponding image to the browser.