[PHP]Hotlink Protection function,��chain protection��
Hotlink Protection is to use the RewriteCond function of Apache to detect the request REFERER when getting a file request, and only the URL of this website is released. This principle is very suitable for the protection of homemade avatars, because avatars should only be used inside this site.
Discuz's built-in avatars are saved in the/forum/images/avatars/directory. I just want to protect these built-in avatars. Users' uploaded avatars and other images do not restrict references, so the RewriteCond code can be placed in this directory::
\--RewriteEngine onRewriteCond% {HTTP\ _ REFERER}! ^ http://chener.net/.\*$ [NC]RewriteCond% {HTTP\ _ REFERER}! ^ http://chener.net$ [NC]RewriteCond% {HTTP\ _ REFERER}! ^ http://chener.net/.\*$ [NC]RewriteCond% {HTTP\ _ REFERER}! ^ http://chener.net$ [NC]RewriteRule.\ *\. (jpg\ | jpeg\ | gif\ | png) $http://chener.net/img/hp.gif [RMagneNC]\
four RewriteCond rule out four ways to visit your own website, namely, visit a page under the site without www, visit the home page of the site without www, visit a page under the site with www and visit the home page of the site with www. HTTP\ _ REFERER except in these four cases, and the file ending with jpg or jpeg, gif, png goes to the http://chener.net/img/hp.gif file.
Save this file as .htaccess and upload it to the/forum/images/avatars/directory. If you want to protect the images of the entire site, upload them to the root directory; if you want to protect files in other formats, add the extension directly in RewriteRule.
by the way: this method has some limitations, such as some download tools can send custom "reference" values; in addition, some users install firewalls and antivirus software that prevent browsers from sending HTTP\ _ references to the server, so their normal browsing will be affected. I don't know what this kind of firewall software vendors think, because it's only about privacy at most (and it's mainly about the privacy of HTTP\ _ REFERER sites, not about visitors), but has nothing to do with network security.
Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/life/PHP-Hotlink-Protection-function-chain-protection.htm