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:
Put it in a directory not accessible to public or use .htaccess to restrict access.
.htaccess file: