PHP picture file Download file anti-theft chain setting method

Source: Internet
Author: User

PHP anti-theft Chain

The code is as follows Copy Code

<?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:

The code is as follows Copy Code

<?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

The code is as follows Copy Code

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:

The code is as follows Copy Code
Rewriteengine on
Rewritecond%{http_referer}!^$
Rewritecond%{http_referer}!^http://(www.)? Www.111cn.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

  code is as follows copy code


[Isapi_ Rewrite]
# 3600 = 1 hour
Cacheclockrate 3600
Repeatlimit #
# 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]

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.