Web Hosting Talk







View Full Version : PHP Script Modification


SLIPKNOT CPD
10-17-2003, 01:39 PM
i was wondering if anyone would be nice enough to modify this text-counter script for me so that it logs daily totals into another text file but while keeping count and displaying total hits :)

<?
$countfile = file("scripts/data/count.txt");
$count=$countfile[0];
$count=$count+1;
$fp = fopen("scripts/data/count.txt","w");
$fw = fwrite($fp,$count);
fclose($fp);
print "$count Total Hits";
?>

anglo_aussie
10-20-2003, 09:45 AM
Simply create a second filename based on todays date. Just use the counter result from the total increment.

<?
function incCounter ($filename) {
$countfile = file($filename);
$count=$countfile[0];
$count=$count+1;
$fp = fopen($filename,"w");
$fw = fwrite($fp,$count);
fclose($fp);
return $count;
}

$dailyfile = "scripts/data/count".date("Y_m_d").".txt";
$totalfile = "scripts/data/count.txt";

incCounter ($dailyfile);
$count = incCounter($totalfile);
print "$count Total Hits";
?>

You may need to accept a value before the incCounter($dailyfile) if you get an error there. Just put a $count = before it, it will get overwritter by the next line.

HTH