PHP implements anti-leech analysis, and php implements anti-leech Protection

Source: Internet
Author: User

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

strrposFunction 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

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.