FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

I have a question about php

 


phileplanet
How would I go about doing this:

I want to have a download counter to count the no. of downloads for one file only. I will have pages A and B. Then i want to have like an if statement that says, if the count reaches a certain number, display pg B. otherwise display pg A. And then (hang tight now), i want to reset the count every day.

So basically, because i don't want to exceed my bandwith, i want to make it so that the file can only be downloaded a certain amount of times per day.

If anyone can help me with this, I will greatly appreciate it.

Thank you all!


Last edited by phileplanet on Sun Apr 23, 2006 5:28 am; edited 1 time in total
sonam
Put very top on your Page A this script. If is certian number reached script will redirect user on Page B

Code:
<?php
$fileName = "count.txt"; // file where is number of downloads
$location = "page B"; // redirect page
   $fp = fopen($fileName, 'rb');
   if(!$fp) {
      echo "ERROR: Unable to open data file!<br />\n";
      exit;
  } else {
      $num = fread($fp, filesize($fileName));
     fclose($fp);
  }
if ($num == 100) {
header("Location:$location");
exit;
}
?>


For new counting every day I must thing little bit.

Sonam
phileplanet
sonam wrote:


For new counting every day I must thing little bit.

Sonam


Looks good sonam but I don't think I want to redirect it. Ideally, I wanted to have an index page which will ure a require function to pull the info from page A or B.


Last edited by phileplanet on Sun Apr 23, 2006 5:28 am; edited 1 time in total
sonam
Ahh, ok, I understand now. In that case is much better to use switch/case function. With switch/case is easy imploding part of HTML in existing page.

Code:
<?php
$fileName = "count.txt"; // file where is number of downloads
$location = "page B"; // redirect page
$maxNum = 100; // max downloads number

$fp = fopen($fileName, 'rb');
   if(!$fp) {
      $change = 2; // switch error message
   } else {
      $num = fread($fp, filesize($fileName));
     fclose($fp);
 
        if ($num == $maxNum) {
            $change = 1; // switch Parth B
        } else {
            $change = 0; // switch Parth A
        }
   }
   
switch($change) {
      case "0": echo "Parth A"; break;
      case "1": echo "Parth B"; break;
     case "2": echo "Sorry, data file is not accessible."; break;
}
?>


Also, I am remove exit function for checking if data file is not accessible because, I thing, is much better to download page completely then partially.

Sonam
phileplanet
Thank you so much for all your help. It is very much appreciated. Unfortunately I wont be using your advice because i wanted a way to do this without using mySQL. But now I have decided that using mySQL will be a better option for me so thank you for your help.

Last edited by phileplanet on Sun Apr 23, 2006 5:28 am; edited 1 time in total
sonam
Quote:
But now I have decided that using mySQL will be a better option for me so thank you for your help.


OK, good luck! Very Happy

Sonam
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.