search
Homephp教程php手册禁止图片盗链

禁止图片盗链

Jun 21, 2016 am 09:09 AM
httpnbsprefererrewritetest

1、假设充许连结图片的主机域名为:www.test.com

2、修改httpd.conf

 SetEnvIfNoCase Referer "^http://www.test.com/" local_ref=1

Order Allow,Deny
Allow from env=local_ref
 
 


这个简单的应用不光可以解决图片盗链的问题,稍加修改还可以防止任意文件盗链下载的问题。

使用以上的方法当从非指定的主机连结图片时,图片将无法显示,如果希望显示一张“禁止盗链”的图片,我们可以用mod_rewrite 来实现。

首先在安装 apache 时要加上 --enable-rewrite 参数加载 mod_rewrite 模组。

假设“禁止盗链”的图片为abc.gif,我们在 httpd.conf 中可以这样配置:


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?test.com /.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.test.com/abc.gif [R,L] 
 


当主机的图片被盗链时,只会看到 abc.gif 这张“禁止盗链”的图片!



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.