开发者

Allow a user to download a file after submitting their email address

开发者 https://www.devze.com 2023-01-17 13:46 出处:网络
I want to allow users to download a file, but in order to do so they have to supply an email address. When they enter their address, a link/code is emailed to them开发者_开发问答, then they have to cl

I want to allow users to download a file, but in order to do so they have to supply an email address. When they enter their address, a link/code is emailed to them开发者_开发问答, then they have to click that link, and the file downloads.

My question is- how can I restrict access to the file so that only people with a valid code can download it? I understand how to create a code, and then how to check the code that the user submits against a list of valid ones, but I don't quite know how to stop the file from being accessable via it's absolute address.


Two methods I can think of:

  1. Use ".htaccess" (HTTP) authentication, keeping the file inside the password protected directory.
  2. Hold the actual file outside of the DocumentRoot, using a PHP script to read in the file and output it to the client (but only if a valid code is supplied) (Don't forget to output a Content-Type header!).


Put it in a directory not accessible to public or use .htaccess to restrict access.

.htaccess file:

order deny,allow
deny  from all
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号