Jump to content

Archived

This topic is now archived and is closed to further replies.

DarkHorizon

PHP help with payment

Recommended Posts

Hi folks, its the age old question...

i have some mp3 files that are available for sale. I want customers to pay for them using paypal then download them once payment has been taken.

I am familiar with PayPal integration into a 3rd party (my) PHP shopping cart.

How do i restrict access to a file on a server such as an MP3 until the user has paid?

Just some rough ideas, a plan would be great. You dont have to offer any code, i know you are busy enough witout me butting in.

Share this post


Link to post
Share on other sites
Place the files in a non accessible directory, with there filenames and paths stored in a database. You then use the [url=http://php.net/header]header[/url] function to force a download once authorized.

Share this post


Link to post
Share on other sites
you could use a variable with a boolean(true/false) value, so that if it's not paid for, say $paid = false,  you restrict the page by checking the value of $paid when the page loads, if false then redirect, otherwhise let them continue.

Share this post


Link to post
Share on other sites
place the files in a no web access directory, then serve them via PHP...


[code]// no web access directory and file paid for!

$file = '/path/paid.mp3';

if ( has been paid logic )
{
if ( not dowloaded already logic OR allowed download time limit logic < time () )
{
header ( 'Cache-control: max-age=31536000' );
header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
header ( 'Content-Length: ' . filesize ( $file ) );
header ( 'Content-Disposition: filename="' . basename ( $file ) . '"' );
header ( 'Content-Type: application/download; name="' . basename ( $file ) . '"' );
readfile ( $file );
}
else
{
echo 'sorry you already downloaded this music file';
}
}
else
{
echo 'sorry you have not paid to use this service!';
}[/code]


me!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.