I am having two separate problems. First, the counter function I’m using for a website periodically resets the value it stores in a text file on the website. I have not been able to figure out why this is. So I’ve been trying to do a workaround to minimize the effects of the counter resetting itself (basically, by periodically storing the value of the counter in the counter.php file, and then manually resetting the actual counter, as it doesn’t seem to reset itself unless the counter is quite high). However, I’ve run into a snag there as well - the variable I use to store the counter value is somehow not storing it as a numeric value.
The gist of it is that I’m storing a numeric value for a counter in a text file. But when I read it out of the text file into a variable, it treats it as a non-numeric value. I’m trying to figure out why this is and am getting nowhere.
Here are the pertinent sections of the php file:
<?PHP include("index.php"); $hitslog = "hits.txt"; // Get the hitslog file ready $hits = file($hitslog); $hits = $hits[0]; if (!isset($_COOKIE['visitcounter'])) { setcookie("visitcounter","site_reference", time()+60*60*24); $hits++; // Opening the hits file and write the number of hits: $fp = fopen($hitslog, "w"); flock($fp,LOCK_EX); fwrite($fp, $hits); fclose($fp); } echo(""$hits." visitors since ".LAUNCHDATE." ^^
"); } ?>LAUNCHDATE is a string constant marking the date that the website launched. As far as I can tell, it has no effect on the counter itself. hits.txt is the file I store the counter in.
I’ve used intval on it, and it returns 0. When I use strval, it returns the number stored in $hits as a string. When I use is_numeric, it returns false. I am having no luck figuring out why.