Let's take a look at the anti-theft judgment of a download address! -Php Tutorial

Source: Internet
Author: User
Let's take a look at an anti-theft judgment! Two websites, one main site, and one uploaded sub-site

The download. php on the main site is the download page.

The sub-station's down. php is the download link

You must click the download link of download. php to download the SDK.
To prevent users from directly accessing the sub-site/down. php? Fileid = 1 can be downloaded to this file and the following judgment is made:

Download. php adds a hash value.
$ Hash = strtoupper (md5 ('downloadkey'. date ('ymmdh ')));

Down. php also adds a hash value
$ Hash2 = strtoupper (md5 ('downloadkey'. date ('ymmdh ')));

Down. php judgment
If ($ hash <> $ hash2) {header ("Content-Type: text/html; charset = utf-8"); echo 'file ID: '. $ file_id .'
'; Echo' ['. $ file_name.'] the file address has expired. Please download it again.

If the problem persists, contact the administrator.

'; If ($ pd_gid = 1) {echo'

---------- The following content administrator can see ----------
'; Echo' file HASH: '. $ hash .'


'; Echo' file HASH2: '. $ hash2 .'
';}


At that time, there was a problem: the user accessed the download page at 20:59:59, and then clicked to download

However, after clicking the button, the time is 21:00:01, so that the hash value is different, and then the download is not allowed. you can download it again after returning it.

How can this problem be solved ..


Reply to discussion (solution)

How can someone!

Is there any other way to avoid using time to generate hash values?

The generated $ hash should be passed through the cookie and have a short validity period, and stored in the session at the same time.
During the check, the system does not generate a new one, but only checks whether the cookie exists and compares it with the session.

The same as the verification code

The generated $ hash should be passed through the cookie and have a short validity period, and stored in the session at the same time.
During the check, the system does not generate a new one, but only checks whether the cookie exists and compares it with the session.

The same as the verification code

Find a simple method

If (strpos ($ _ SERVER ['http _ referer'], 'http: // www.domain.com ') = 0)
Determine whether the router address is feasible or not.


The generated $ hash should be passed through the cookie and have a short validity period, and stored in the session at the same time.
During the check, the system does not generate a new one, but only checks whether the cookie exists and compares it with the session.

The same as the verification code

Find a simple method

If (strpos ($ _ SERVER ['http _ referer'], 'http: // www.domain.com ') = 0)
Determine whether the router address is feasible or not.
This can be forged.

HTTP_REFERER can be forged.

You can refer to basic authentication.

Conversely, simulating a browser is also a subject. So this is a matter of height. Anti-theft can only prevent normal leeching. it cannot be absolutely prevented if you use a program to simulate web pages.

Therefore, we recommend that you use referer anti-Leech instead of anti-bot.

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.