显示图像且不允许热链接
我们需要在页面中显示约 40 个图像,并且不允许用户热链接这些图像。我们当前使用 ,它指向检查
cgi.http_referer
并使用 cfcontent 显示图像的处理程序
。但是,某些图像将无法加载(40 个图像中约有 6 个),如果我刷新页面,其他一些图像将无法加载。
当我必须显示超过 10 张图像时,似乎会出现此问题。我想这是因为我正在使用 cfcontent ?如果是这样,我应该用什么来代替?
We need to display ~40 images in a page and not allow users to hot link those images. We are currently using <img src="...">
which points to a handler that checks the cgi.http_referer
and display the images using cfcontent
. However, some images will fail to load (~6 images out of 40), if I refresh the page, some other images will fail to load.
This problem seems to appear when I have to display more than 10 images. I suppose this is because I'm using cfcontent
? If so, what should I use instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要准确找出这些图像失败的原因,您需要做更多的工作。您应该使用 FireFox 中的 Firebug 或 Safari 或 Chrome 中的控制台等工具来找出那些失败的请求发生了什么情况。您还可以使用 Fiddler on Windows for IE 或 Mac、Windows 或 Linux 上的 Charles 查看后台发生的完整 HTTP 请求,以及来自 ColdFusion 应用服务器的完整返回值。在您确切知道他们失败的原因之前,我们无法提出任何解决方案。
另一件要记住的事情是,如果您通过 ColdFusion 执行此操作,那么对于每个页面加载,您都会向 CF 服务器发送 40 个以上的请求。因此,一页会导致 CF 服务器有 41 次点击进行处理。确保代码尽可能紧凑。
如果我要走这条路,我会在服务器级别(IIS 或 Apache)使用某种服务器级别过滤器来防止热链接。但请记住,总会有办法解决它。
To find out exactly why those images are failing, you'll need to do a little more work. You should use something like Firebug in FireFox, or the console in Safari or Chrome, to find out what's happening with those requests that are failing. You can also use something like Fiddler on Windows for IE or Charles on the Mac, Windows, or Linux to see the full HTTP requests that are happening in the background, along with the full return values from your ColdFusion app server. Until you know exactly why they're failing, we can't come up with any sort of solution.
The other thing to remember, is that if you do this via ColdFusion, then for every page load, you're hitting your CF server with 40 more requests. So one page then results in 41 hits to your CF server for processing. Make sure that code is as tight as it can possibly be.
If I was going to go this route, I'd do it at the server level (IIS or Apache) using some sort of server-level filter to prevent the hotlinking. But just remember, that there will always be a way around it.