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