Php anti-Leech settings for image file downloads. The simplest anti-Leech method in php is to use the $ _ SERVER [HTTP_REFERER] function of php to operate the anti-Leech function. However, this method is not reliable and we still need to use apache in the end, the simplest anti-Leech method for iis operations in php is to use the $ _ SERVER [\ 'http _ REFERER \ '] function of php to operate, but this method is not reliable, in the end, we still need to use apache and iis for operations. I will share the introduction below. if you need it, please refer to it.
Php anti-Leech
The code is as follows: |
|
Session_start (); Session_register ('check '); $ _ SESSION ['check'] = true; ?> |
Check the session variable and determine whether to visit the home page. Check whether the source webpage reference (HTTP_REFERER) is from the webpage of the local website.
The method is as follows:
The code is as follows: |
|
Session_start (); $ Refs = parse_url ($ _ SERVER ['http _ referer']); // refer to webpage information for decomposition. // Check whether the home 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-Leech protection. if you understand it a little bit, you can crack it,
Use the server to set php anti-theft connection
Apache anti-Leech
Modify httpd. conf
The code is as follows: |
|
SetEnvIfNoCase Referer "^" local_ref = 1 Order Allow, Deny Allow from env = local_ref |
If you want to display an image "anti-leeching", you can use mod_rewrite.
Add the -- enable-rewrite parameter to load the mod_rewrite module when installing apache.
Assume that the image of the anti-Leech feature is abc.gif. we can configure it in httpd. conf as follows:
The code is as follows: |
|
RewriteEngine on RewriteCond % {HTTP_REFERER }! ^ $ RewriteCond % {HTTP_REFERER }! ^ Http: // (www .)? Hzhuti.com/. * $ [NC] RewriteRule. (gif | jpg) $ abc.gif [R, L] DocumentRoot "/usr/local/apache/htdocs" # Set the directory for storing html files of the website. Options FollowSymLinks AllowOverride None |
Iis anti-Leech
Select c: RewriteRewrite. dll as the execution file.
Httpd. ini is the configuration file
Image anti-Leech code
The code is 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]
|
...