PHP implementation of picture files and download file anti-theft chain method,
This article describes the PHP implementation of image files and download file anti-theft chain method. Share to everyone for your reference. The specific analysis is as follows:
The simplest anti-theft chain method in PHP is to use PHP's $_server[' http_referer ' function to operate, but this method is not reliable, we will eventually need to use Apache,iis to operate, the specific operation method is as follows:
PHP anti-theft chain:
Copy the Code code as follows: <?php
Session_Start ();
Session_register (' check ');
$_session[' Check ']=true;
?>
Check the session variables to determine whether to visit the homepage. And check if his source page reference (Http_referer) is from a local Web page.
Here's how:
Copy the Code code as follows: <?php
Session_Start ();
$refs = Parse_url ($_server[' http_referer '); Decomposition of reference web information
Check if the main page session and source host are the same
if (! ( $_session[' check ') | | $refs [' host ']! = $_server[' Http_host ')
Exit
?>
Note: This can only be a simple anti-theft chain, if you understand a little bit can be cracked,
Use the server to set up PHP anti-theft connection
Apache Anti-theft chain:
Modify httpd.conf:
Copy the Code code as follows: Setenvifnocase Referer "^" local_ref=1
Order Allow,deny
Allow from Env=local_ref
If you want to display a "no hotlinking" picture, we can use mod_rewrite to achieve.
First, when installing Apache, add the--enable-rewrite parameter to load the Mod_rewrite module.
Assuming that the "Prohibit hotlinking" picture is abc.gif, we can configure this in httpd.conf:
Copy the Code code as follows: Rewriteengine on
Rewritecond%{http_referer}!^$
Rewritecond%{http_referer}!^http://(www.)? Www.jb51.net/.*$ [NC]
Rewriterule. (gif|jpg) $ abc.gif [r,l]
DocumentRoot "/usr/local/apache/htdocs"
#设置存放站点html文件的目录.
Options FollowSymLinks
AllowOverride None
IIS anti-theft chain:
Execute file selection C:rewriterewrite.dll that's it.
Httpd.ini is a configuration file
Picture anti-theft chain code
Copy the Code code as follows: [Isapi_rewrite]
# 3600 = 1 hour
Cacheclockrate 3600
Repeatlimit 32
# Protect Httpd.ini and Httpd.parse.errors files
# from accessing through HTTP
Rewritecond Host: (. +)
Rewritecond Referer: (?! http://1.*). *
Rewriterule. *. (?: gif|jpg|png|bmp)/force.gif [I,o]
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/904934.html www.bkjia.com true http://www.bkjia.com/PHPjc/904934.html techarticle PHP Implementation of image files and download file anti-theft chain method, this article describes the PHP implementation of picture files and download file anti-theft chain method. Share to everyone for your reference. A specific analysis such as ...