Jump to content


Photo

PHP help with payment


  • Please log in to reply
4 replies to this topic

#1 DarkHorizon

DarkHorizon
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationScotland

Posted 19 October 2006 - 01:54 PM

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.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 19 October 2006 - 01:58 PM

Place the files in a non accessible directory, with there filenames and paths stored in a database. You then use the header function to force a download once authorized.

#3 Design

Design
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationThe Computer Chair

Posted 19 October 2006 - 02:01 PM

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.

#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 19 October 2006 - 02:06 PM

place the files in a no web access directory, then serve them via PHP...


// 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!';
}


me!

#5 DarkHorizon

DarkHorizon
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationScotland

Posted 19 October 2006 - 02:19 PM

thanks,

now i can make a start on building it up..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users