This article describes the PHP implementation of picture files and download files Anti-Theft chain method. Share to everyone for your reference. The specific analysis is as follows:
In PHP, the simplest anti-theft chain approach is to use PHP's $_server[' http_referer ' function to operate, but this method is not reliable, we eventually need to use the Apache,iis to operate, the specific operation methods are as follows:
PHP anti-theft chain:
Copy Code code as follows:
<?php
Session_Start ();
Session_register (' check ');
$_session[' Check ']=true;
?>
Check session variables to determine whether to visit the home page. And check that his source page reference (Http_referer) is from the local Web site's Web page.
The method is as follows:
Copy Code code as follows:
<?php
Session_Start ();
$refs = Parse_url ($_server[' http_referer ')); Decomposition Reference web Information
Check home 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 a little bit of understanding can be cracked,
Use the server to set up the PHP burglar connection
Apache anti-theft chain:
Modify httpd.conf:
Copy Code code as follows:
Setenvifnocase Referer "^" local_ref=1
<filesmatch ". (gif|jpg) ">
Order Allow,deny
Allow from Env=local_ref
</FilesMatch>
If you want to display a "no hotlinking" picture, we can use the mod_rewrite to achieve.
First, add the--enable-rewrite parameter to load the Mod_rewrite module when you install Apache.
Suppose the "Prohibit hotlinking" picture is abc.gif and we can configure this in httpd.conf:
Copy 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文件的目录.
<directory/>
Options FollowSymLinks
AllowOverride None
</Directory>
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 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 will help you with your PHP program design.