Hi ,
Could some one help me out to count the hits made on a page(created in html).I want the number of people accessing a particular portal .
Thanks,
Aswathy
Hi ,
Could some one help me out to count the hits made on a page(created in html).I want the number of people accessing a particular portal .
Thanks,
Aswathy
This thread is about counting hits on a plain HTML page. and pointed toward ready-made counters and reported it worked. Below are concise, practical options and a minimal, reliable example for readers who prefer a lightweight self-hosted counter.
Common approaches and tradeoffs: use a full analytics package for rich metrics (pageviews, sessions, bounce rates); parse server logs for raw, server-side hits (includes bots); or add a tiny server endpoint that the page calls (AJAX or image beacon) so counts survive edge caches. Important cautions: caches and CDNs can hide hits unless the counter call bypasses cache; automated bots inflate raw hit numbers unless filtered; file-based counters are fine for low traffic but need locking to avoid race conditions; for scale use a database with an atomic increment.
Minimal, safe single-file counter (PHP) — place this behind a non-cached request and call it from the page:
<?php
$file = __DIR__ . '/counter.txt';
$fp = fopen($file, 'c+');
if ($fp === false) exit('0');
if (flock($fp, LOCK_EX)) {
rewind($fp);
$count = (int)trim(stream_get_contents($fp));
$count++;
rewind($fp);
ftruncate($fp, 0);
fwrite($fp, (string)$count);
fflush($fp);
flock($fp, LOCK_UN);
}
fclose($fp);
echo $count;
?> Notes: compare any counter against server logs for validation; switch to a DB or analytics service for higher traffic or richer reporting; always consider privacy and cookie/consent requirements when deploying third-party trackers.
Jump to Post— Member #114696To do that you need some sever side coding. There are also some ready made scripts too. See this
http://chami.com/counter/pnp/
To do that you need some sever side coding. There are also some ready made scripts too. See this
http://chami.com/counter/pnp/
It is not worth coding it yourself really. Just grabone form the link above
thank you ..........i did that
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.