i have two sripts : one of them counts visits per day (writes to counter.txt), another one - total visits (writes to counter_2.txt). is it possible to put them together?
per day:
total:
per day:
| Quote: |
| <?php
//get the current date (formatted as "08/10/2005") $today = date ("d/m/Y"); //open the file //line 0 (1 for non programmers ) contains the date //line 1 (2 for non programmers )contains the number of visits $file = file("counter_2.txt"); $line = 0; foreach ($file as $data) { if ($line == 0) //line 0 => format the stored time $time = date("d/m/Y", $data); if ($line == 1) //line 1 => stored visitors $count = $data; $line++; } //if the day isn't the current day, set the count to zero if ($time != $today) $count = 0; //add one for the current visitor $count = $count + 1; // Display the number of hits echo "<p>Today: " . $count . "</p>"; // To disable output to webpage quote the above line using // //construct the 2 line from the count.txt $lines2write = time() . "\n" . $count; //write the lines to the file $fp = fopen("counter_2.txt", "w"); fwrite($fp, $lines2write); fclose($fp); ?> |
total:
| Quote: |
| <?php
$fp = fopen("counter.txt", "r"); $count = fread($fp, 1024); fclose($fp); $count = $count + 1; // Display the number of hits echo "<p>Total: " . $count . "</p>"; // To disable output to webpage quote the above line using // $fp = fopen("counter.txt", "w"); fwrite($fp, $count); fclose($fp); ?> |
