I need a php script to limit download

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pornmasta
    Too lazy to set a custom title
    • Jun 2006
    • 20016

    #1

    I need a php script to limit download

    I want that to rpevent that a user download more that (let's say) 3 files in a day.
    And i need a php script to do this.

    Does someone has a free solution ?
  • misfit138
    Registered User
    • Nov 2006
    • 2

    #2
    you can use php sessions... example;

    <?php
    session_start();

    if (!session_is_registered('count')) {
    session_register('count');
    $count = 1;
    } else {
    $count++;
    }
    ?>
    <?
    if ($_SESSION['count']>="3") {
    ?>you have reached you download limit...etc...
    <? } else { ?>download code here<? } ?>

    hope this helps ;)
    Click Cash Content

    Comment

    • pornmasta
      Too lazy to set a custom title
      • Jun 2006
      • 20016

      #3
      in fact i programmed this:

      Code:
      <?php
      
      $fifi = @$_GET['file'];
      $dlimit = 2;
      $tlimit = 86400;
      
      if (!$fifi) {echo "error"; exit;};
      
      
      $sites[1] = array("somewhere", "somewhere");
      $sites[2] = array("somewhere", "somewhere");
      $sites[3] = array("somewhere", "somewhere");
      
      
      
      
      
      function dl_file_resume($fi1,$fi2)
      {
      
      //$tailleFichier = remote_file_size($fi1);
      header('Content-Type: application/octet-stream');
      //header("Content-Length: $tailleFichier");
      header("Content-Disposition: attachment; filename=\"$fi2\"");
      readfile($fi1,$fi2);
      }
      
      
      
      
      
      if (isset($_COOKIE['TimeCookie'])) {
         foreach ($_COOKIE['TimeCookie'] as $name => $value) {
      
      
      if ($value<$dlimit) { 
           // echo "$name : $value <br />\n";
      
      
      
      setcookie("TimeCookie[1]", $value+1, time()+$tlimit);
      
      dl_file_resume($sites[$fifi][0],$sites[$fifi][1]);
      
      
      
      }
      else {echo "Download limit reached, try again 24 hours after your last download";
      exit;
      }
         }
      }
      else {
      
      $value = '1';
      
      setcookie("TimeCookie[1]", $value, time()+$tlimit);  /* expire dans une heure */
      
      dl_file_resume($sites[$fifi][0],$sites[$fifi][1]);
      
      }
      
      
      ?>

      Comment

      Working...