Any ideas? I would prefer not to use one of those free things tied to someone elses server.
Thanks,
BuddyB

Dani AI

Generated

Since confirmed a server-side language is available (as asked) the safest path is a self‑hosted counter rather than a third‑party widget. Three practical approaches suit most sites: a simple file counter (easy, but watch race conditions and permissions), a database counter (robust and atomic), or server‑log analysis (most accurate and low overhead). ’s PHP snippet is a useful quick start for small sites, but the following clarifications and examples cover common gaps: concurrency, unique‑visitor logic, bots, and scaling.

For a reliable, low‑effort implementation use a small DB table and an atomic query. The table needs a primary key on the page identifier; then an INSERT ... ON DUPLICATE KEY UPDATE keeps increments safe under concurrency:

CREATE TABLE counters (
  page VARCHAR(255) PRIMARY KEY,
  hits INT UNSIGNED NOT NULL DEFAULT 0
);

$stmt = $pdo->prepare(
  "INSERT INTO counters (page, hits) VALUES (:page, 1)
   ON DUPLICATE KEY UPDATE hits = hits + 1"
);
$stmt->execute([':page' => $page]);

To count unique visitors instead of raw pageviews, set a short‑lived cookie and only increment when it is absent. This is simple, widely compatible, and keeps PII out of the store — but it isn’t perfect (cookies cleared, multiple devices, shared IPs). If the site serves EU users, cookie consent and privacy rules should be considered before setting tracking cookies.

Operational tips: file‑based counters must use locking (flock) and correct permissions or they’ll corrupt under concurrent requests. For higher traffic, use an in‑memory counter (Redis/Atomic INCR) or append hits to a log and aggregate in a cron job to avoid DB write storms. Filter obvious bots by User‑Agent and exclude known crawl paths, but treat bot filtering as a best‑effort measure. Finally, present counts as plain text/CSS, keep the display accessible, and avoid external hosted images or scripts that reintroduce the very dependency wanted to avoid.

Recommended Answers

All 6 Replies

Do you have a server side language like php or asp available on your server?

Yes I do have.
BuddyB

I've run across a treasure trove. Thanks for bumping me along.
BuddyB

no probs. once you know how to find things like that then you're away.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.