My original answer:
You will need to store (be in a database or a session variable) which elements the user can receive, for each you create a unique random token. This token will be used to identify purchased goods. Pass the token to the page where they will be loaded (either in the session variable, or in the POST argument, or as the last option in the URL, i.e. GET). On the page, when you need to download, you will query the database / session variable, using the session information to identify the client and the transferred token (however you transferred it), and with this, extract the file to download.
If you need to keep a list of purchased items for reloading, you can also do this, but remember to create tokens again when the user requests a download. You can also add an expiration date if you like it.
Now I have mentioned a couple of alternatives, and then by the nature of the answers given, I think you will need more detailed information on how to do this.
Maybe Ernie is right, and I should not assume that you have a session. Maybe I should show you how to do the session.
So, I'll take one of the implementation options, the easiest option.
<?php
Now on the download page ....
<?php
Please note that I only allow access to the file with PHP, so I can first check if the user has access. You should not allow the user to simply put the URL (even he cannot guess) and access the file. Therefore, if you use your server, you want to place these files outside the server’s web folder, or if you use the hosting protected by it with .htaccess (or another mechanism provided by your hosting).
In accordance with this decision:
It is simple, easy to implement. However, it has some disadvantages:
- If the session ends before downloading, the user has lost his money *.
- There is no clear way to implement reloading.
- It is still vulnerable to session hijacking (far away, I know, but it's better to be safe).
*: Say that the connection was lost and the session expired in the client. Oh no, we don’t need happy customers.
So, you really need to restore this using the database and create random tokens, preferably with an expiration date.