Problem getting this code to write over 9999 to counter2.txt file ???
Im very much a novice.
At first it writes and displays 10000 then on page reload or an additional visit it reverts to 1000 and the 1001 etc etc.
Im sure its a simple fix ??
<?php
session_start ();
// get current hit
$opFile = fopen ("counter2.txt", "r");
$handle = fread ($opFile, filesize ("counter2.txt"));
fclose ($opFile);
// if new session
if (!isset ($_SESSION['hit'])){
// set session
$_SESSION['hit'] = TRUE;
// add the hit
$handle = $handle + 1;
// print javascript
echo 'document.write("'.$handle.' Hits");';
// put new hit to db
$opFile = fopen ("counter2.txt", "w");
fwrite ($opFile, $handle);
fclose ($opFile);
// else
}else{
// print only
echo 'document.write("'.$handle.' Hits");';
}
?>