TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,965
  • Latest: boruko
Stats
  • Total Posts: 195,980
  • Total Topics: 21,320
  • Online today: 281
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 123
  • Total: 124
  • @rjen

Daily Counter Script

Started by tim antley, September 05, 2007, 05:07:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ianedres

This is a very simple daily hit counter. It will increment the count on each view until the next day (determined by your server's date) which will reset back to 1.

This is slightly different from my first version posted on TP Lite during the server changeover.

The script defaults to displaying the counter, but if you place 'silent' in the URL (with a ? between the scriptname and 'silent') if will suppress the output yet still increment the counter.

There is no error checking for file access; errors are suppressed also.

If you place in a block, remove the '<?php' from the first line and '?>' from the last line.

<?php

// Daily Counter Script
// September 4, 2007
// Tim Antley - www.bayoumx.com

// For Use With SMF & TinyPortal

// Stores the day of week and hit count in a file.
// If current day is same as file's day-stamp, counter is incremented by one.
// If day is different, counter resets to 1.

// Specify 'silent' in URL will suppress output after incrementing count.
// Place a question mark between script name; ie. daily_counter.php?silent

// There is no error checking for the file.

$counter_file 'daily_counter.csv'; // can use your own filename here.

// Should not have to edit anything below this line.

$today getdate(); // Array for today's information

$handle = @fopen($counter_file"r"); // Read-only access

$data = @fgetcsv($handle1000','); // Reads file comma-separated values & places into array $data.

@fclose($handle);

$counter $data[1];

if(
$data[0]==$today['mday']) // Check file's day-stamp against current day.
{
$counter++;
}
else
{
$counter=1;
}

$output $today['mday'].', '.$counter; // Format output into comma-separated values for file.

$handle = @fopen($counter_file"w");

@
fwrite($handle$output);

@
fclose($handle);

if(!isset(
$_GET['silent'])) // Display output unless 'silent' appears in URL.
{
echo $counter;
}

?>

jdvarner

cool. works. would be cooler if it was unique hits vs counting everytime i hit refresh or went into another page.

Ianedres

I thought about that also- however, with my PHP coding at a very elementary level, it was the best I could do for now.  8)

This website is proudly hosted on Crocweb Cloud Website Hosting.