Share:
Notifications
Clear all

How can we add page views in PHP?

a70c51106900eba242692ba52c12d253?s=110&d=mm&r=g
(@vishaljaiswal)
Member Admin

Pages views or hits counter in PHP for website.

Quote
Topic starter Posted : 11/05/2022 8:22 pm
a70c51106900eba242692ba52c12d253?s=110&d=mm&r=g
(@vishaljaiswal)
Member Admin
<?php

$filename = "count.txt";// the text file to store count
// Open the file foe reading current count
$fp = fopen($filename, 'r');

//Get exiting count
$count = fread($fp, filesize($filename));

//close file
fclose($fp);

//Add 1 to the existing count
$count = $count +1;

//Display the number of hits
echo "<p>Page Views: " . $count. "</p>";

//Reopen to modify content
$fp = fopen($filename, 'w');

//write the new count to file
fwrite($fp, $count);

//close file
fclose($fp);

?>
ReplyQuote
Topic starter Posted : 11/05/2022 8:23 pm
Share: