Let's take a look at the anti-theft judgment of a download address! How to solve

Source: Internet
Author: User
Let's take a look at an anti-theft judgment! Two websites & nbsp; one main site & nbsp; one download of the sub-station main site for upload. php & nbsp; indicates the download page sub-site down. php must use download. php download click link to download in order to prevent direct access to the & nbsp; sub-site down. php? Fileid1 can be downloaded to this file & nbsp; The following is 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. '] 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 ..

Share:


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

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.