Reputation: 121
I have an problem on my website i've made an hits counter :
$count = ("hits.txt");
$clicks = file($count);
if ($clicks > 5){$clicks = 0;}
$clicks[0]++;
$fp = fopen($count , "w");
fputs($fp , "$clicks[0]");
fclose($fp);
but i receive this message : cannot use a scalar as an array warning issue
Upvotes: 0
Views: 71
Reputation: 39532
Woah - I don't know what's going on in your code here.
file
to read the file instead of a simple file reader? Use fopen
, file_get_contents
or other solutions to simply read a number off a text fileYour example could very easily be rewritten to the following:
<?php
$count = (int)file_get_contents("hits.txt");
file_put_contents("hits.txt", ($count > 10 ? 1 : $count + 1));
?>
Upvotes: 1