1

我有一个包含图片 1.jpg、2.jpg、3.jpg 的文件夹...有什么方法可以阻止用户直接在浏览器中键入 www.example.com/pictures/3.jpg 之类的 URL 并加载该图像?

如果 web html 调用它(< img href=...),则应该加载图像。

那有可能吗?使用 IIS URL 重写或其他一些技术?

我正在使用 IIS7.5。我的目标是防止用户看到下一张图片...我知道,我可以对名称进行编码,但我有一些从 1 到 1000 的旧数据库,我想以某种方式阻止用户不使用 url 浏览没有推荐人......因为我每天都在提供一张照片,我不希望他们找到其余的......

这有可能吗?

4

1 回答 1

1

You can try it with a url rewrite by relying on HTTP_REFERRER but that's not always accurate and could possibly block users on some browsers from seeing the images on your site as well.

If I were you I would move all of your images outside your web directory (or preferably just block the pictures folder altogether) and then build a php script like this called image.php:

<?php

define('NUM_IMAGES', 1000);

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

$image = imagecreatefromjpeg('pictures/'.((int)(time()/86400)%NUM_IMAGES+1).'.jpg');
imagepng($image);

?>

The script above will output an image to the users browser which will change once a day to the next image in sequence and you can use it like: <img src="image.php" />

Then, since your images folder is blocked, nobody can see any other image. Then can still request image.php directly but they'll only see the image of the day.

If you don't want to rotate automatically once a day and want manual control over which image it shows you can also just replace the '.((int)(time()/86400)%1000+1).' with the number of the image you want to display .

If you do want it to rotate automatically, but want to control the time it updates at you can add an offset to time() like: ((time()+$offset)/86400)

于 2011-07-24T20:26:52.300 回答