i want to create this thing but i have no clue how to start
Moderator: General Moderators
i want to create this thing but i have no clue how to start
I want to create something where special users have special privilleges. For example a guest is only allowed to download one file a day, how do I keep track of it so that the user cant do things like clear his cookie or end the session to by past this, if you tell me a way to keep track of it, I can write the code myself. Thanks
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
You could have a cron job that runs at midnight everyday.
Or you could have a wrapper class for downloading a file - if there has been a download that day, then it returns false [as in denied the right to download].
Heres something to start you off
Or you could have a wrapper class for downloading a file - if there has been a download that day, then it returns false [as in denied the right to download].
Heres something to start you off
Code: Select all
create table downloads (
filename varchar(64),
member int(10) unsigned,
timestamp datetime,
id int(30) unsigned primary key auto_increment
);- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: i want to create this thing but i have no clue how to st
You need to write some code for a user account system. It is a fairly large subject and there is probably plenty of code in this forum if you search. You will need an log-in page for authentication and some code to do Access Control on the pages that you want to have "special privilleges" on. Then you can start on something for limiting downloads to a certain number per timeframe. The easiest would be to just add a column to the user account database table that held the date/time of the last download. Then you can only allow access to downloads if it has been a day since the date of the last download in the user's account. Each time the user does a download you update the last download date in their user record.soul814 wrote:I want to create something where special users have special privilleges. For example a guest is only allowed to download one file a day, how do I keep track of it so that the user cant do things like clear his cookie or end the session to by past this, if you tell me a way to keep track of it, I can write the code myself. Thanks
(#10850)
Using cron for this is silly,
although cron jobs would work here it is really overkill.
You need a datetime field in your table and you just store the timestamp of the last download (this is on your users table), when they go to download again you check if the current value returned by time() is greater then the value in the database multiplied by how many seconds in a day (3600*24), if so they haven't downloaded in the past 24 hours. If you want to actually reset it every night at midnight one could argue cron is better but I'd disagree, you can still work something out with the php time functions
main reason for avoiding cron here is portability (your code will run anywhere timestamps are available) and if that cron fails to run for whatever reason (server reboots when it is set to run or something) you're restricting your users from downloading for periods longer then one day
although cron jobs would work here it is really overkill.
You need a datetime field in your table and you just store the timestamp of the last download (this is on your users table), when they go to download again you check if the current value returned by time() is greater then the value in the database multiplied by how many seconds in a day (3600*24), if so they haven't downloaded in the past 24 hours. If you want to actually reset it every night at midnight one could argue cron is better but I'd disagree, you can still work something out with the php time functions
main reason for avoiding cron here is portability (your code will run anywhere timestamps are available) and if that cron fails to run for whatever reason (server reboots when it is set to run or something) you're restricting your users from downloading for periods longer then one day
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
I do not understand why you are bringing cron,,,this is such easy
example table
Date downloads MemberId
18/01 2 5
19/01 1 5
Lets say you want to check whether member with id 5 has reached his limits. Let's say the max download is two per day. First check for
select downloads from table_name where MemberId = $memberId and Date = date(sysdate());
if no rows returned create a row,
insert into table_name values(date(sysdate), 1, $memberId);
If already an entry exists, update row
update table_name set downloads = downloads + 1
Now just before you update make sure that that downloads limit is not exceeded
example table
Date downloads MemberId
18/01 2 5
19/01 1 5
Lets say you want to check whether member with id 5 has reached his limits. Let's say the max download is two per day. First check for
select downloads from table_name where MemberId = $memberId and Date = date(sysdate());
if no rows returned create a row,
insert into table_name values(date(sysdate), 1, $memberId);
If already an entry exists, update row
update table_name set downloads = downloads + 1
Now just before you update make sure that that downloads limit is not exceeded
Yes, I would like to reset it at midnight but checking the time with each click makes very good sense.
I'm thinking of doing it by bandwidth/files depending on the membership. Shouldn't be hard, two tables one for bandwidth used one for the # of files dled, same table. I'll write up a simple login script today, I rather code myself without stealing code, it takes the fun out of things.
I'm thinking of doing it by bandwidth/files depending on the membership. Shouldn't be hard, two tables one for bandwidth used one for the # of files dled, same table. I'll write up a simple login script today, I rather code myself without stealing code, it takes the fun out of things.
jshpro2 has hit the button, use a time() comparison to check for a 24hour period between downloads..
Just remember to update the lastDownload field when the user does download.
Code: Select all
function allowDownload ($userid)
{
$sql = "SELECT `lastDownload` FROM `users` WHERE `userid` = '{$userid}'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if ((intval($row['lastDownload']) + 86400) > time()) {
//user has downloaded a file within the last 24hrs..
return false;
} else {
return true;
}
}