Download, then unlock

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
pomdah
Forum Newbie
Posts: 3
Joined: Mon Nov 22, 2010 9:01 am

Download, then unlock

Post by pomdah »

I am building a PHP site for a small business where the customer should be able to download a file and then get a key in the mail to unlock it when he/she has paid. Anybody who knows where to find methods for this?
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Re: Download, then unlock

Post by DaveTheAve »

Have the original uncompressed file uploaded to a non-public folder on the site, then when the user pays for it, have PHP run the command line to compress the orginal file to a /tmp file with the key you will email the buyer and present that compressed file to the buyer to download.
pomdah
Forum Newbie
Posts: 3
Joined: Mon Nov 22, 2010 9:01 am

Re: Download, then unlock

Post by pomdah »

Thanks, sounds simple enough. Could you give some advice about compression/encryption methods, too?
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Re: Download, then unlock

Post by DaveTheAve »

Code: Select all

system('zip -P pass file.zip file.pdf');
Simple enough and should give you a nice idea.

Also, This should help you as well.
pomdah
Forum Newbie
Posts: 3
Joined: Mon Nov 22, 2010 9:01 am

Re: Download, then unlock

Post by pomdah »

Thanks again, embarrassed I didn't find that myself.
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Re: Download, then unlock

Post by DaveTheAve »

Don't worry about it. I ask lots of questions here and half the time I feel stupid too. It's just a part of learning!
Bind
Forum Contributor
Posts: 102
Joined: Wed Feb 03, 2010 1:22 am

Re: Download, then unlock

Post by Bind »

Another option would be to encrypt the pdf file itself on the fly with php. You can also use php to automatically generate the pdf file as well, and use php do allow them to download it upon payment (with automatic confirmation like through paypal verifying it with their IPN API).

You could also design an entire system for it. User accounts allowing them automatic and immediate access to the resource they have paid for, right away when they make their payments. PHP can then stream them the pdf from a protected directory.

... which would eliminate the need to "protect" and "unlock" your pdf's.

Automation is a good thing. Saves valuable time and money.

PHP's PDF Manual
Protect PDF Files with PHP
PayPal Instant Payment Notification (IPN) Introduction
PayPal Instant Payment Notification (IPN) Code Samples
Post Reply