PHP implementation of picture files and download files anti-theft chain method _php Skills

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.