473,799 Members | 3,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Secure downloads - how to link to file?

I use a download script to allow users to download files that are not in a
publicly accessible directory. The files should only be downloadable from a
secure page which only authenticated users have access to. But how do I
prevent someone from running the download script? The hyperlinks in the
secure page point to the download script which is in a public directory. If
the script is not in a public directory, the links fail.

The secure page look like this:

<?php
session_start() ;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<link href='../../style.css' rel='stylesheet ' type='text/css'>
<title>Secure Page</title>
</head>
<?php
if (validate($_SES SION'uid]'))
{
[echo a bunch of html with hyperlinks]
<a href='mydownloa dscript.php?nav =somefile.zip'> somefile.zip
}

The download script looks like this:

<?php
$filename = ($_GET[nav]);
$dlfile = "/home/private/directory/".$filename ;
header("Content-Disposition: attachment; filename=".$fil ename);
header("Content-Length: ".filesize($dlf ile));
readfile($dlfil e);
?>

Obviously, this isn't secure because someone could guess (or sniff) the
filename. I've tried to do something like this:

[mydownloadscrip t.php]
<?php
session_start()
if ($_SESSION['uid'])
{
$filename = ($_GET[nav]);
$dlfile = "/home/private/directory/".$filename ;
header("Content-Disposition: attachment; filename=".$fil ename);
header("Content-Length: ".filesize($dlf ile));
readfile($dlfil e);
}
?>

but then readfile() fails because of problems with the header information
caused by session_start() .

Is there a better way? Other alternatives?

Thanks in advance.
Jul 17 '05 #1
1 3699
"deko" <de**@hotmail.c om> writes:

Is there a better way? Other alternatives?


Have a look at http://pear.php.net/package/HTTP_Download .

It would be a good idea to keep the files you want to send across in a
directory that is out of the webserver's DocumentRoot.

The cod snippet that you sent across has quite a few security holes in
it too.
--
Raj Shekhar Y! : Operations Engineer
MySQL DBA, programmer and slacker Y!IM : lunatech3007
home : http://rajshekhar.net blog : http://rajshekhar.net/blog/
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1819
by: cjundang | last post by:
I wan't to display all process in Unix system. In compile time, it didn't have a problem but link time is show error message "ps.o (.text+0x9a): undefined reference to pfind" "pfind" is a function that implement in file /sys/kern/kern_proc.c and its prototype is in /usr/includ/sys/proc.h My program is named myps . It is included sys/proc.h. I can compile is but can not link it. How to solve this problem. Please tell me. thank you very...
0
1081
by: anthony.mescall | last post by:
I have an adp file which I want to be accessed using forms only for security reasons. I have a front end which closes off underlying Access window, but it is still possible to connect to the underlying adp via a second mdb file. In Access mdb, encryption was possible - what can be done with an adp file to restrict access via a linked file. It looks like Microsoft reduced security options for adp files, presumably to rely in
3
1461
by: Brian Tkatch | last post by:
I'm trying to get more information on connect via .NET to UDB. On <URL:http://www-128.ibm.com/developerworks/db2/zones/vstudio/> there is a link "CBT: Fast path to DB2 UDB in a Visual Basic .NET environment" <URL:http://www.ibm.com/software/data/education/l1630.html">, yet i see nothing there about .NET. We have UDB 8.1.6. and would like to know if we must upgrade to 8.2 to be able to use .NET to access the database.
2
3257
by: deko | last post by:
I have files on my Apache web server that are NOT in publicly accessible space. I want to make these files available for download only to authenticated users. I currently use a download script that is accessed from an SSL-encrypted page (that the user arrives at after authenticating). There are links in this page that initiate the different file downloads by passing a variable (name of the directory and file) to the download script. ...
1
1818
by: Bigrabid | last post by:
Howdy, I have an access database that I use to keep track of projects that my group is working on. There are a number of files associated with any one project, so I have as a parent to , which holds file paths for all of the most important files (for easy access and tracking) and a short description of what each file is. Now, sometimes a file (or a whole directory) will be moved from outside the confines of the database, or the project...
5
3772
by: learning | last post by:
Hi it's my first time to post something on the net. Hope someone can help me with this. I just started learning how to program with php (about a month ago), so pls. bear with me. So far, i've made a simple retrieval of my database (a list of names). With each name as a LINK to display the details of that name. if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result))
3
3204
by: ykhamitkar | last post by:
Hi There, I want to add a file management system in my application I have a form with a textbox(datatype hyperlink) and a button 1. User clicks on button 2. one file dialog apears 3. User selects file 4. clicks on ok 5. Path of the file comes in the textbox
0
14299
ADezii
by: ADezii | last post by:
Rather than using CurrentProject.Connection or entering your own Connection information, ADO supports storing Connection information in an external file called a Data Link File (which normally has a *.UDL extension). Data Link Files provide two very important capabilities: They implement a graphical interface for constructing what can be complex and confusing OLE DB Connection Strings. They offer a way to allow Users to edit Connection...
0
1829
abdoelmasry
by: abdoelmasry | last post by:
Hi Guys i need help to secure IIS6 on windows server 2003, I am creating Web Hosting server which host many web sites, i found that any script can Read any file from windows directory and this is security risk, although i have set anonymous user for every website, i think that happens because allow read permission is set by default on windows folder for (Authenticated Users) group,
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.