473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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($_SESSION'uid]'))
{
[echo a bunch of html with hyperlinks]
<a href='mydownloadscript.php?nav=somefile.zip'>somef ile.zip
}

The download script looks like this:

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

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

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

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 3592
"deko" <de**@hotmail.com> 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
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...
0
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...
3
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...
2
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...
1
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...
5
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...
3
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...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...

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.