Here’s how it works:
- User makes a payment
- User receives a password
- Their user name will be their email
- A folder will be created for that user, which contains the files the user paid to have access to.
My main problem is that the software needs to be protected, and the password will be dynamically created. So I’m wondering if I need to create an .htaccess and a .htpaaswd, if that’s the case, how would can I do this dynamically?
Probably the same way WordPress creates/modifies a .htaccess file.
You simply need to create a script that will generate the correct file contents for a .htpass or a .htaccess file.
When a user purchases something, add a line to the .htpass file that contains the user/pass combination, and all them to a group (probably based on filename). Then, only allow that group to access that file.
Another way to do this would be through databases.
First, when the user makes a payment, have a few tables to store their data.
First Table: User/Password
This stores the email/password combination that must be used to gain access to the users files. Basically the table consists of
int Unq_ID|text Email_Addr|varchar(150) PasswordThat holds your user/pass combinations.
Second Table: Files
This table holds all of your files names, IDs and where they are created.
int Unq_ID|varchar(150) Name|text DirectoryThird Table: Relationship
This last table holds the relationship between the User and the Password. Also very simple:
int Unq_ID|int User_ID|int Product_IDBasically, if the person logs in with a valid Username/Password, you go grab relationship entries that match their
User_ID, and join the files with on theProduct ID. To verify they can download something, simply check that an entry exists that has the rightUser_IDandProduct_ID.To protect a file from being accessed, make an htaccess file like this
RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^.+$ [NC] RewriteRule .* - [F,L]which deny from anyone accept PHP’s fopen function. Then you just create a PHP script that grabs the contents, and presents it as a download.