What I am trying to accomplish is a simple PHP pageview counter for each of my PHP pages, I know this can be accomplished with MYSQL database as well, but I just want a simple page view counter with strictly PHP (Which I already accomplished).
I already found a script that works, but it only displays views for one page, I was wondering, if there was a way to edit the code so that with each page I include the counter, the number of views would be different for that page.
The website I found the instructions to follow is http://tutorial.world.edu/web-development/how-to-create-page-view-hit-counter-code-using-php-script/
And this is my code, that I edited to my needs:
function pageview_counter()
{
if (isset($visitor)) {
if ($visitor == "visited")
include("pageview-counter.txt");
} else {
$file = fopen("pageview-counter.txt", "r+");
$result = fread($file, filesize("pageview-counter.txt"));
fclose($file);
$result += 1;
$file = fopen("pageview-counter.txt", "w+");
fputs($file, $result);
fclose($file);
include("pageview-counter.txt");
}
}
And for the counter:
<p class="num-of-views">Views: <strong><?php echo pageview_counter(); ?></strong></p>
I created the text file in my website directory as directed, I just want to know if what I want can actually be accomplished. Any help will be greatly appreciated!