Clan Adverts

Custom PHPNuke Scripts

 

Limit Downloads to Registered Members

Description: With large user base there are times when you need to limit their access to downloads. This can be helpful with bandwidth usage. This tutorial will show you how to limit downloads for registered members daily, weekly, monthly or yearly.
Version: 1.0
Added on: 23 January 2008
Author: Admin
Difficulty Level: Intermediate
Views: 222
Detailed Profile

Files to edit:
modules/Downloads/index.php

Steps :
1. The first step requires you to use phpmyadmin or other database management software to add the following queries. Select your phpnuke database and insert the following sql. Change "nuke" to your prefix if is different.

Code:
CREATE TABLE `nuke_userdls` (
  `id` int(11) NOT NULL auto_increment,
  `user_id` int(11) NOT NULL default '0',
  `ws_date` varchar(255) NOT NULL default ',
  PRIMARY KEY  (`id`)
);


Our next step is to edit the Downloads index.php file to limit the access.
Open modules/Downloads/index.php and find the following function.

Code:
function getit($lid)


Directly under the globals within that function paste the following.

Code:
   global $user, $cookie, $sitename;   
   //ADDED BY WESTERN STUDIOS.NET
    $daylimit = 3; //Change this to amount daily
   $weeklimit = 10; //Change this to weekly limit   
   //First let's get the userid
    cookiedecode($user);
    $userid = $cookie[0];
   //done
   //today downloads
   $ws_num_tday = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_userdls WHERE user_id='$userid' AND CURDATE() = ws_date"));
   //done
   //week
   $ws_num_week = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_userdls WHERE user_id='$userid' AND DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= ws_date"));
   //Done

/* THE FOLLOWING CAN BE USED FOR MONTHS AND YEARS
   //Month
   $ws_num_month = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_userdls WHERE user_id='$userid' AND DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= ws_date"));
   //Done
    //Year
   $ws_num_year = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_userdls WHERE user_id='$userid' AND DATE_SUB(CURDATE(),INTERVAL 365 DAY) <= ws_date"));
   //Done
*/
   //Now let's block the subscriber from downloading if they have reached their limit. It would be also nice to give them a message that they are too greedy.. :)
if(($ws_num_tday >=$daylimit || $ws_num_week >=$weeklimit) && !is_admin($admin)){
//Let's tell them they can't download for a while.
$pagetitle = "- You have reached your limit";
       include("header.php");
       title("$sitename: Download Limit Exceeded");
       OpenTable();
      echo "<center><b>Download limit exceeded</b><br><br>Your are allowed <b>".$daylimit."</b> Downloads per day and <b>".$weeklimit."</b> downloads per week.<br>"
                 .""."<br>"._GOBACK."";
       CloseTable();
       include("footer.php");
       die();
}   

   
if($userid !=1){
$db->sql_query("INSERT INTO ".$prefix."_userdls VALUES(NULL, '$userid', CURDATE())");
}


You should edit only the $daylimit and $weeklimit Change both to the amount of downloads you would like to allow for each member.

I left monthly limit and yearly limit in the mod if needed.

Tutorials ©