FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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!
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.
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.
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
Related topics
PHP Write to line
php admin and mysql admin console
php variables
PHP, MySQL...
Smilies question, PhP forum.
PHP question
question aux codeurs ! php noob InsiDe!!
php nuke question
Question: PHP scripting + cron jobs
A quick PHP Question! You know the answer! Answer ASAP .
MySQL and PHP Question
php or python question about some processing.
Do you think the Universe has a end to space?
PHP question about passing variables (noob)
The moon moving too close to the Earth?....
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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