473,765 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Files downloadable by members only

Hello,

I want to set some files downloadable only by members with login and
password.

I use session to protect my .html and .php files, but I would like to know
how to protect .zip files.
The .zip files are in a folder protected with a .htaccess file with the
members data as password file.
When a member is already connected and click on a download link, a connect
dialog box ask the member to fill again his login and password (of course to
get in the protected folder).

I would like to know if there is a way to avoid this dialog box, or if i
should use something else to protect the files.

I appreciate any advice,

Fred.
Jul 17 '05 #1
4 2067
Boniface Frederic wrote:
Hello,

I want to set some files downloadable only by members with login and
password.

I use session to protect my .html and .php files, but I would like to
know how to protect .zip files.
The .zip files are in a folder protected with a .htaccess file with
the members data as password file.
When a member is already connected and click on a download link, a
connect dialog box ask the member to fill again his login and
password (of course to get in the protected folder).

I would like to know if there is a way to avoid this dialog box, or
if i should use something else to protect the files.


Put your files in a directory, where they can't be accessed directly, either
outside the webroot or in a password-protected folder.
Then access the files via eg getfile.php?nam e=some.file
getfile.php checks the authorisation, and if ok, sets the proper
mime-headers fopens /protected/some.file, and emits it using fpassthru()

Leif
Jul 17 '05 #2
Thank you Leif for the fast and accurate response.
Here is the getfile.php code if someone is interested.

Fred.

// getfile.php :
<?php
session_start() ;
if(empty($_SESS ION['login']))
{
// not a member
die('Member access only');
}
else
{
//---- check file
if (is_file($file) )
{
// ----- Open the file
$fp = fopen($file, "r");
// ----- Content Type
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename=".$fil e);
//Download
fpassthru($fp);
}
else
print('File '.$file.' not found');
}
?>
Jul 17 '05 #3
"Boniface Frederic" <bo************ ***@free.fr> wrote in message news:<40******* *************** *@news.free.fr> ...
Thank you Leif for the fast and accurate response.
Here is the getfile.php code if someone is interested.
// getfile.php :
<?php
session_start() ;
if(empty($_SESS ION['login']))
{
// not a member
die('Member access only');
}
else
{
//---- check file
if (is_file($file) )
{


So... here $file is $_GET['file']? So, you allow any filename
(file path) to be sent via the query string? Don't you see any
security threat?

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #4
"Boniface Frederic" <bo************ ***@free.fr> wrote in message
news:40******** *************** @news.free.fr.. .
Thank you Leif for the fast and accurate response.
Here is the getfile.php code if someone is interested.

Fred.

// getfile.php :
<?php
session_start() ;
if(empty($_SESS ION['login']))
{
// not a member
die('Member access only');
}
else
{
//---- check file
if (is_file($file) )
{
// ----- Open the file
$fp = fopen($file, "r");
// ----- Content Type
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename=".$fil e);
//Download
fpassthru($fp);
}
else
print('File '.$file.' not found');
}
?>


Don't forget to call session_write_c lose() before calling fpassthru (or
readfile). Otherwise the visitor would be unable to browse the site while
the file is downloading.
Jul 17 '05 #5

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

Similar topics

1
1846
by: dave | last post by:
Hello, I've got a situation where i have a directory called "example". In this area i have three files, an index page that has a form on it in to which user's can authenticate, a page displaying either success or failure and if success redirects to a downloadable file. I don't want this downloadable file to be had by a direct url access, user's should have to authenticate to get it. I want to use php4 for this and if possible since this is...
3
3747
by: Matthew Moran | last post by:
I am creating a series of downloadable articles, career tools, spreadsheets, etc. However, some of the content is for "registered" guest. The registrants are stored in a database and logon. I want to ensure that someone registered cannot simply pass someone the path to the files for download. However, I am not creating an actual system user name for the folders where the various documents exist.
3
2289
by: Steven Burn | last post by:
The application; Service on my webserver that allows a user to upload their HOSTS file for functions to verify the contents are still valid. Uses; 1. XMLHTTP (MSXML2) 2. FileSystemObject 3. CrazyBeavers Upload control (couldn't get the Dundas one to work)
3
1798
by: Fabrizio | last post by:
HI, I'm trying to create an aspx page that lists all files that an user can download from a site simply clicking on the link. There is any example on the web? Thanks, Fabrizio
1
1342
by: grzybek | last post by:
Hi, I have question about techniques of using files in SQL Server in Web Application. Assuming that I send files from my Web App ( client ) to server and located these files on hard disk ( on server ), I'd like to view these files and I want to have possibilities to open it. How can I do it ? My only one idea is :
1
288
by: Hongbo | last post by:
Hi, We have a web site which needs user to login. After login, there are some files available for download on some pages. A typical link of such file is like this one: https://www.ourdomain.com/docs/contracts/c_02102006.pdf I noticed that any one could get this file if the person knows this link regardless if this person has logged in or not. Is there a way to prevent people who do not login to reach such downloadable files? Thank...
35
1928
by: Nosferatum | last post by:
Ok, I have been told that it's not a good idea to store binary files (like pdfs etc.) in MySQL, but in the file system. I am in desperat need of a system where I can upload binary files like this, categorize them, add some extra info to each file, and list them/make them downloadable. (listing and making files downloadable is easy with PHP). If I upload each file to a folder in the web server file system, how is it then that I can refer...
14
3644
by: lalit | last post by:
Hi there, Can some plz suggest me a way to show .ppt files on my website that can't be copied or saved by user using asp.net. any idea !!!! thankx
1
1836
by: djnokturnal | last post by:
Hey guys/gals, I have successfully implemented forms authentication on my site: <authentication mode="Forms"> <forms loginUrl="/Members/Login.aspx" timeout="20" defaultUrl="/Members/Welcome.aspx" protection="All" requireSSL="false" path="/" /> </authentication> Now I would like to restrict certain subfolders within /Members by Role. I have the following roles for testing:
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10161
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
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8831
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
7378
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
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.