Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-06-2008, 06:38 AM Secure Downloads
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
So I'm seeking to implement a downloads system and want to control the downloads so they are exclusive to a certain membership of users.

What steps should I take to secure my downloads?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
Old 10-06-2008, 09:59 AM Re: Secure Downloads
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Host all the files below the Public HTML (so their hidden) and pull up the files via file which confirms a timestamp is correct.

Essentially:
PHP Code:
<?php
$url_to_files 
'\home\name\files\\';
$filename $_GET['ID']; // should be number.
if($_POST['timestamp'] == $_SESSION['timestamp'] && is_readable($url_to_files.$filename.'php')){
// Include a file in that directory with data about the files and maybe some headers. 
include($url_to_files.$filename.'php'));
# below is an example of the file #
// it's a PDF
header('Content-type: application/pdf');
// force them to download
header('Content-Disposition: attachment; filename="filename.pdf"');
// Make it so the file is not cached
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// send em the file
readfile('filename.pdf');
unset(
$_SESSION['timestamp']);
} else {
echo 
"FAIL!";
}
?>
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 10-06-2008 at 10:05 AM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-07-2008, 02:34 AM Re: Secure Downloads
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
OMG

and get your site down on some dozens of concurrent requests

If you need to secure your downloads for a serious amount of requests you need to install something like nginx or lighhtpd as a frontend and setup it accordingly.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-07-2008, 02:35 AM Re: Secure Downloads
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
lighttpd of cource
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-07-2008, 04:32 AM Re: Secure Downloads
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
Thanks rogem.

So application/pdf I replace pdf with whatever the file extension is? zip, rar etc?

And regarding lighthttpd etc, how neccessary is this?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 10-07-2008, 07:15 AM Re: Secure Downloads
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Lighttpd is absolutely neccessary if you intend to have more than 100 users who may download at the same time, especially if your files are large enough.

Readfile() will try to read the whole file into memory and will not release it until the transfer is complete, so e.g. if 100 users will request a 10Mb file at the same time you will quickly lose 1G of memory which will quite definitely lead to swapping and probably to server stop responding at all.

You may replace readfile() with reading by blocks, but in this case you will have to support Range header (required for resuming downloads and parallel downloads) while lighttpd will handle it by design.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Secure Downloads
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23967 seconds with 12 queries