473,414 Members | 1,575 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,414 software developers and data experts.

limit downloads

Jezternz
145 100+
Ok I have a registration/permissions system setup, and I want to limit different user groups to only allow for an amount of downloads. (and non-logged in users to not have the ability to download anything at all). The files are stored in a public directory on my web server. I have a decent php knowledge and have worked with mysql a fair bit, so database stuff is no probs.
Any ideas on how I could limit user access to files?

Thanks, Josh
Sep 24 '08 #1
7 1616
Markus
6,050 Expert 4TB
I haven't done much (any) work in this area so, my ideas may not be the best. I apologise in advance.

You could log, in the database, the time their last download was and check it against the current time to see if x amount of time has passed. If so, allow the download, else, don't.

Cheers.
Sep 24 '08 #2
Atli
5,058 Expert 4TB
If the files are in a public directory you won't have any control over it.

You would have to either put it outside the web-root, where it can't be reached via a URL, or into a database, where you would have to use a script to fetch it.

Either way you could simply log each download and check that total amount. If the user is allowed to download it, just set the appropriate Content-Type header and echo the contents of the file from wherever it is actually stored.
Sep 24 '08 #3
Jezternz
145 100+
yeh, I will be logging the users activity / download count ect, thats not a problem.
So say I had a folder outside the root directory say "downloads" how would I go about fetching the files for download (I realize it would be in something like download.php?f=bytes.exe) but how do I actually bring up the download?
Also will this apply for uploads as well? can i allow some restricted users to upload to the dir.

Thanks, Josh
Sep 24 '08 #4
pbmods
5,821 Expert 4TB
Heya, Josh.

Use readfile() to send the file data to the browser (http://php.net/readfile).
Sep 25 '08 #5
Jezternz
145 100+
awesome thanks guys. Last thing, when choosing target location for uploads, can i use the same principle, and choose a location not in the public domain?

Thanks heaps, Josh
Sep 25 '08 #6
Jezternz
145 100+
Just wanted to leave a note for anyone the future who has a similar problem.
You may use what PhMods said, by uploading files to a place not in public_html, so in a private directory, then using readfile to read them.
Also a good mysql query that allows you to check how many logged downloads a user has downloaded (which i used) is:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM records WHERE userid = '".mysql_real_escape_string($userid)."' AND DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= date_downloaded
  2.  
This checks from a download-records table how many downloads have been done in the past "1 day" or 24 hours.

Thanks, Josh
Nov 1 '08 #7
Markus
6,050 Expert 4TB
awesome thanks guys. Last thing, when choosing target location for uploads, can i use the same principle, and choose a location not in the public domain?

Thanks heaps, Josh
Yes. To put it simply.
Nov 1 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: deko | last post by:
I have a login script that creates a SESSION for authenticated users. But authenticated users still need access to particular directories (which contain files for download). My hosting provider...
3
by: Brian Piotrowski | last post by:
Hi All, I'm trying to run a simple query from an ASP page. I want the query to select each individual field in a table and compare it to another table. If the value doesn't exist, I want it...
9
by: James Macbell | last post by:
I think I have pushed ASP.NET to the limit, I am not sure if I have done anything wrong in the code because I am trying to make 2 pieces of code (C# vs PHP) using the same algorithm. Anyways, here...
12
by: chipgraphics | last post by:
:confused::confused: I have been on the quest to find a php script that can serve files for downloads and limit the speed at which the file is transfered to the user. I want a faster download...
1
by: coosa | last post by:
Hi all, I get this message when trying to update a tabel i have which has nested hierarchies. The current hierarchies beginning from root = 1 are up to the level 5. Before going into details and...
16
by: google | last post by:
Hello, I am working on an Acc2003 app for my company. In the interest of reducing chances of corruption due to unstable network connectivity, I would like to either prevent users from running it...
1
by: Harold | last post by:
Hi, I'm writing software which should download some files. I want to limit the number of simultanioulsy downloads to two. I'm using the ServicePointManager object for this. But I still can...
1
by: bigpoppa | last post by:
Hey, I need a script that will limit download speed and I want it integrated into the script I am using below. The script below forces downloads and hides url paths and logs stastics of downloads and...
32
by: Nu | last post by:
I want to protect myself from if someone with a fast connection hammers my site. It's not denial of service attacks, but offline downloaders (of course that don't show they're offline downloaders...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...
0
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...

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.