PHP implements anti-leech analysis, and php implements anti-leech Protection
This article describes how to implement anti-leech protection in PHP. We will share this with you for your reference. The details are as follows:
$_SERVER['HTTP_REFERER']
Obtain information
Note:$ _ SERVER ['HTTP _ referer'] cannot always be obtained. It can only be obtained in the following situations:
1. The following conditions can be obtained for HTTP_REFERER:
1. directly use <a href>
2. Form submitted with Submit or <input type = image> (POST or GET)
3. Form submitted using Jscript (POST or GET)
2. The following situations cannot be obtained:
1. Link from favorites
2. Click home or custom address.
3. Use location. href or location. replace () of Jscript ()
4. Enter the address in the browser.
5. <% Response. Redirect %>
6. <% Response. AddHeader %> or <meta http-equiv = refresh> redirect
7. Load the address in XML
strrpos
Function Description:
Strrpos-calculate the position of the last occurrence of the specified string in the target string
Description
int strrpos ( string $haystack , string $needle [, int $offset = 0 ] )
Returns the position of the last occurrence of the needle in the string $ haystack.
$ Haystack |
Search for this string. |
$ Needle |
If needle is not a string, it is converted to an integer and considered as the sequential value of the character. |
Return Value
Returns the position of the needle. If no value is found, FALSE is returned.
Leeching judgment code: asd. php
<? Php // anti-leech technology // first determine whether the $ _ SERVER ['HTTP _ referer'] variable if (isset ($ _ SERVER ['HTTP _ referer']) is obtained. {// determine whether $ _ SERVER ['HTTP _ referer'] is an if (strpos ($ _ SERVER ['HTTP _ referer'] starting with HTTP: // localhost/, "http: // localhost") = 0) {echo '';} else {header ("Location: warning. php "); // jump to the page to warning. php // echo $ _ SERVER ["HTTP_REFERER"] ;}} else {header ("Location: warning. php ") ;}?>
Warning. php
<Html> <B> reverse link </B>
Anti-leech Verification Code
<! DOCTYPE html>
The above is how it works.
Generally, you can configure Server anti-leech protection, such as nginx access configuration.
(Gif | jpg | jpeg | png | bmp | swf) file whitelist
The specific configuration can be searched by Baidu