FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Download System Help





tchaunt
I am wanting to allow people to purchase certain things that they can download from my website. Of course, it would be things that I made. I am wanting the payment to go through PayPal. Here's the concept I've came up with:

Each download has its own page. Each page provides the name of the download, the file type, a description about the download, any other needed content, and-of course-the download button.
My problem is, how do I allow guests to download things only after they've paid with PayPal? I started thinking, and I decided that the person would purchase a key code off of each page using PayPal's buy now feature. After I receive the notice of the purchase, I'll add a randomly generated key-code to a database. When a user clicks download, they will be redirected to a page asking them to type in their key code. If it is wrong, it will ask for the key code again. If it is right, it will begin the download. As soon as the download starts, the key code will be deleted out of the database.

This idea is obviously very rough, and a lot could go wrong. So I was wondering, what is a better way to do this? I really don't want to have to upload any scripts because I have dial-up, and it's incredibly slow. I would preferably want to use only PHP and MySQL (and obviously HTML and CSS) on the site. Any help/input on this subject will be appreciated.
rvec
Why no just set a cookie/session-var that they paid for something and check for that on the file-page. Then as an extra security you might not want to link them directly to the file but open the file with php and send it to the user (to prevent direct linking).

Also I think you should give the paypal api a good look. You might not need it, but it can give you some extra features you wouldn't have with the normal buttons. You'd have some more security and better integration with paypal.
tchaunt
^^
What do you think about this idea:
Have a page with the description and title and what not, and then have the "Buy Now" button. Then, have them go through the process. For the result page (after successful transaction), I could set the cookie or session-var and tell them that they have one hour to download or what ever.

What's the code to use for opening the files with PHP? I was wondering how to prevent people from figuring out the file's name, and it sounds like that could work.
rvec
combine these with an echo and you can send the user any file you want from your php script.
http://nl2.php.net/function.file-get-contents
http://nl2.php.net/manual/en/function.header.php

You could also mail them a link with a key (www.example.com/get.php?filename=test&mode=download&key=hv99n4f89snroa9u3rnaef09wj3fnsaef)
And associate the key with a file. Then when someone visits the page you can set a cookie with the key in it.

The problem with sessions is that they can't close the browser. If you send them a mail you can also keep records of your custommers.
tchaunt
Thanks for all of the help! I'll check it out.
tchaunt
Crap. I think I'm doing something wrong. I'm getting this instead of the page:
"Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /usr/home/tchaunt/domains/tchaunt.frih.org/public_html/test.php on line 2

Warning: file_get_contents(http://tchaunt.frih.org/blah.zip) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /usr/home/tchaunt/domains/tchaunt.frih.org/public_html/test.php on line 2"
So does anyone know what I'm doing wrong?
rvec
yeah that's blocked. You can't use an url in those functions. You could try using the curl functions, I think those aren't blocked.
tchaunt
Um.....okay? I'll google it and check it out. Or maybe scan those pages even harder in case I missed something.
rvec
http://nl.php.net/curl

forgot to give that link in the last post.
tchaunt
Thank you so much for all the help. I'll read the page and edit when I get the results.
tchaunt
I'm having so much trouble right now. I can nor get the cUrl to work. I'm not given any errors, but the download will not start.
rvec
Code:
<?php
//set the url to download
$url = 'http://www.frihost.com';

//start curl
if (function_exists('curl_init'))
{
   // create a new cURL resource
   $ch = curl_init();

   // set URL and other appropriate options
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   // grab URL and pass it to the browser
   $curl = curl_exec($ch);

   // close cURL resource, and free up system resources
   curl_close($ch);

   if ($curl!='')
      echo $curl;
}
//end curl

//start fopen
//create a new file handler
$handle = fopen($url, "rb");

//get the contents of the url
$fopen = stream_get_contents($handle);

//close the handler
fclose($handle);

if ($fopen!='')
   echo $fopen;
//end fopen


if you get the frihost website there at least one of the methods works. You can comment one out to see which one works. I think at least one works on every server, but I don't remember which worked on which server.
tchaunt
The cUrl script worked on my server. The problem is, I'm getting frihost.com to come up by using it, but I can't get the ZIP download started. Have I missed some sort of rule or something?
Here's what I've used:
Code:
<?php
//set the url to download
$url = 'http://tchaunt.frih.com/blah.zip';

//start curl
if (function_exists('curl_init'))
{
   // create a new cURL resource
   $ch = curl_init();

   // set URL and other appropriate options
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   // grab URL and pass it to the browser
   $curl = curl_exec($ch);

   // close cURL resource, and free up system resources
   curl_close($ch);

   if ($curl!='')
      echo $curl;
}
//end curl
?>


When you view the page source though, it is just blank. I just thought of something. Do I need to pardon the back-slash (/) with a forward slash (\)?

EDIT: I tried using the forward slash character to "pardon" certain characters, and it didn't work. It's still just coming up blank.

EDIT2: I'm an idiot. I just realized that I typed .com instead of .org. I'll fix that and update.

EDIT3: Okay. I got it to work. It even unzipped the file--a simple text file that says blah, blah, BLAH!
Will it do the same for mp3s?

EDIT4:
It didn't work when I tried to use an mp3 in a zip file.Any ideas of what went wrong? I didn't even use .com this time! XD
rvec
you have to change the header to make that work.
Add this before the echo:
Code:
header('Content-Type: application/zip');


and best would be to do a bit of .htaccess magic to make the file have a .zip extension.
This would forward all requests for filename.zip to getzip.php
Code:
RewriteEngine On

RewriteRule filename.zip getzip.php [L]


If you have your script in getzip.php and link to filename.zip, users will download a file called filename.zip with the output of getzip.php as the contents.
tchaunt
Now, for the header to work, the file that I want to be downloaded has to be compressed right?

Also, since I'm just starting to get into much advanced PHP, I'm not sure, where should I put the .htaccess thing at/how do I get it to work?
rvec
the .htaccess isn't php. It's an extra file with directives for apache. You have to make a file called .htaccess (in windows you have to use command line to make it) and put the above script in it.

more info about .htaccess:
http://httpd.apache.org/docs/1.3/howto/htaccess.html

and yeah that header tells the browser you're sending a .zip file, so other files will also work, but they'd be send to the browser as if they where .zip files.
tchaunt
I was thinking it was something outside of PHP, but I couldn't remember. Thanks for correcting me. Smile

Again, thanks for the information.

EDIT: I forgot to mention, I haven't the slightest clue on how to actually use the command line correctly. I have played around with it, and that's about it.
rvec
make a new file, open prompt (start->run('cmd')) and rename the file to .htaccess with the command ren :
http://www.ss64.com/nt/ren.html
Related topics
*OFFICIAL* Which Browser do you use?
FTP Codes
FTP error codes -- What they mean
Download Studio - A great Download Manager.
Memory (RAM) Problem
Login System help
Emoticon System Help
php download system prob
logging problems
BSOD oh no! Need help
CISCO Aironet wireless card driver needed
eBooks related to Web Design etc for FRIH$
php home system help
NEED MEMBERS AND GAMERS!!!!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.