用于反热链接的PHP代码 [英] PHP code for anti hotlinking

查看:82
本文介绍了用于反热链接的PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的站点中,我们正在执行图像保护部分.因此,作为图像保护的一部分,我们需要 为图片提供反链接.在我们的网站中,我们使用生成的url显示图片.

In our sites we are doing a image protection section. So as a part of image protection we need provide antihotlinking for images.In our site we are showing the image using a generated url.

例如,在我们的网站中,图像来源为:image_file.php?type=image&w=10&h=10&i=12

For example in our site the image source is like: image_file.php?type=image&w=10&h=10&i=12

(出于示例目的,这只是一个伪造的网址).

(this only a fake url for example purpose).

因此,使用此url我们需要在我们的网站中显示图像,同时要防止其热链接,是否有任何方法可以防止热链接?

So using this url we need to show image in our site and at the same time want to prevent it from hot linking is there any way for prevent hotlinking?

推荐答案

图片热链接通常由引荐来源检测到,但在以下情况下不起作用:

Image hotlinking is usually detected by referer, but it won't work when:

  • 用户已关闭浏览器中的引荐来源发送(出于隐私目的,我使用了此功能)
  • 页面是通过HTTPS查看的(浏览器不应发送引用数据).

您将阻止实际用户查看图像.

You'll block your actual users from viewing images.

在处理此问题时,请考虑使用会话/Cookie.然后,您必须通过php脚本传递每个图像.

这篇关于用于反热链接的PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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