Skip Navigation
GutterStar.net Home...
The World Famous Hit CounterRelated Resources: Web and Software Development Download Center
AboutChange Log:
V3.0: Added: Now supports dynamic updating of hit statistic values at runtime, without any page refresh. Watch your hit statistics literally change before your eyes while looking at your web page!
V2.1: Fixed: All of the include statements for automatically created variable files have been modified to check whether the file exists before running, which was causing problems for PHP5 users when these conditional statements were missing. All's well now though.
V2.0: Fixed: Includes a large bug fix regarding the accurate counting of the days of the current month, which effects the tracking of users currently online.
IntroductionIs this PHP script really world famous? Sure it is! Why not?!
So now, the exciting part, what exactly does the hit counter script do? Actually it does quite a lot. Essentially, this script is a hit counter, which tracks the number of visitors to your website.
First it measures the total number of hits for all time. Then it measures the number of hits for that particular day. Also, it measures the number of users that are currently browsing your website at that particular moment.
In addition to these basic features, you have the option to keep a history log. This feature will save the hit statistics every day, after midnight, to the history log file on the server. The format for the history log file is this, each line represents one day's activity, and the line is delimited by camas. The first section records the date for which that line represents, the second section records the total number of hits for that day, and the third section records the maximum number of users browsing your site at the same time, including the exact time that the peak activity occurred! This is very useful if you wish to know the dates and times that your site is most popular.
If you enable the auto email notification feature, you can have the contents of the history log file emailed to you at the end of each month! This process will reset the history log, so you won't have to receive the same content along with the new content each time.
The cama delimited format of the history log file is perfect for importing directly into most database applications, so tracking your website statistics will be simple.
A couple of other unique features include...
This script can be run invisibly in the background, so your analytics tracking can be done without any additional user impact.
Also, though this is a PHP script, it is possible to use this script within standard HTML pages using JavaScript! That's right... This script merges PHP with JavaScript to directly pass the necessary variables from PHP to JavaScript variables within the current document object!
Now, when using the JavaScript implementation, you can choose to have your hit statistic values automatically update themselves on your page, without any page refresh! This is truly a dynamic hit counter.
So what does this look like?The following code is available within the "Sample.htm.php" file, which is included in the download.
To display each value within a PHP page using the available variables, the following method will work...
<?
include("./hit_counter.php");
echo "The current total number of hits to date is $total. Today, there have been $today visitors. There are currently $cTotal users currently online. The most users that were online at the same time today ($hDate), were $hTotal at $hTime. The most users that were ever online at the same time were $maxTotalOnline, on $maxTotalOnlineDate at $maxTotalOnlineTime.";
?>
Alternatively, to display each value within a standard HTML page using JavaScript variables, the following will work...
<script type="text/javascript" src="./hit_counter.js.php"></script>
<script type="text/javascript">
document.write('The current total number of hits to date is ' + total + '. Today, there have been ' + today + ' visitors. There are currently ' + cTotal + ' users currently online. The most users that were online at the same time today (' + hDate + '), were ' + hTotal + ' at ' + hTime + '. The most users that were ever online at the same time were ' + maxTotalOnline + ', on ' + maxTotalOnlineDate + ' at ' + maxTotalOnlineTime + '.');
</script>
To use the truly advanced JavaScript functionality, and have your statistics automatically update themselves every minute without a page refresh, the following syntax will work...
<script type="text/javascript" src="hit_counter.js.php"></script>
The current total number of hits to date is <script type="text/javascript">
document.write('<span id="sTotal">' + total + '</span>');
</script>. Today, there have been <script type="text/javascript">
document.write('<span id="sToday">' + today + '</span>');
</script> visitors. There are currently <script type="text/javascript">
document.write('<span id="scTotal">' + cTotal + '</span>');
</script> users currently online. The most users that were online at the same time today (<script type="text/javascript">
document.write('<span id="shDate">' + hDate + '</span>');
</script>), were <script type="text/javascript">
document.write('<span id="shTotal">' + hTotal + '</span>');
</script> at <script type="text/javascript">
document.write('<span id="shTime">' + hTime + '</span>');
</script>. The most users that were ever online at the same time were <script type="text/javascript">
document.write('<span id="sMaxTotalOnline">' + maxTotalOnline + '</span>');
</script>, on <script type="text/javascript">
document.write('<span id="sMaxTotalOnlineDate">' + maxTotalOnlineDate + '</span>');
</script> at <script type="text/javascript">
document.write('<span id="sMaxTotalOnlineTime">' + maxTotalOnlineTime + '</span>');
</script>.
<script type="text/javascript" src="dynamicHitScheduler.js"></script>
All three of these methods will print the hit counter statistics as follows...
The current total number of hits to date is 117332. Today, there have been 41 visitors. There are currently 10 users currently online. The most users that were online at the same time today (Thursday March 11; 2010), were 12 at 1:18 AM. The most users that were ever online at the same time were 136, on Wednesday July 1; 2009 at 2:26 PM.
Notice that these hit counter statistics directly reflect those displayed at the top right of this page. Also, the main site hit counter (at the top right of the page) is using the dynamic JavaScript implementation, so if you stare at it long enough, you will see the statistic values change by themselves... Pretty awesome ey?
To run the hit counter invisibly in the background, simply use the following procedure...
For PHP, insert the line:
<? include("./hit_counter.php"); ?>
For JavaScript, insert the line:
<script type="text/javascript" src="./hit_counter.js.php"></script>
So... What about setup?Simply follow the instructions contained within the file: "hit_counter_config.php". A copy of this file's content follows...
<?
/* Relative folder where the supporting hit_counter files are stored. Must not end with a slash. Examples include...
If the hit_counter files are stored in "domain.com/hit_counter", and the hit_counter script is being included within a page at "domain.com", the relative folder should be set to $relativeFolder = './hit_counter';
However, if the hit_counter files are being stored at "domain.com/hit_counter", and the hit_counter script is being included in a page at "domain.com/mySubFolder/directory", the relative folder should be set to $relativeFolder = '../../hit_counter';
The default balue '.' assumes that all of these files will be referenced from the same folder as the given web page, where the PHP statement '<? include("hit_counter.php"); ?>' is located. */
$relativeFolder = '.';
// Save log of hit count statistics? true or false
$logHistory = true;
/* Send email log statistics at the end of each month? The log will automatically be cleared after the message is sent. $logHistory must be set to true for this feature to work.
Enter the email address that you wish the log to be sent to. Example: 'example@domain.com'
Or leave this variable blank to automatically skip this feature. The log will not be cleared at the end of each month if left blank. */
$sendLogTo = '';
// The message displayed at the beginning of the log email.
$email_header = "Excelent! Your latest website statistics are ready! You lucky webmaster you...\n\n";
// The following date and time formats will be used when recording log statistics.
$historyDateString = 'l F j; Y';
$historyTimeString = 'g:i A';
/* The maximum time to detect when users are currently online. This number is reflected in the $cTotal variable, and refers to the number of users currently browsing your site at the moment. */
// The specified number of hours.
$time_hours = 0;
// The specified number of minutes.
$time_minutes = 10;
// The specified number of seconds.
$time_seconds = 0;
/* Okay... Now what?
1. After uploading all of these files, give the file named "hit_counter_history.txt" a permition of 766, to allow the file to be written to at runtime.
2. If all of these files are in the same folder as the page or pages that will include the hit_counter script, this file should be uploaded to the same folder.
However, if the hit_counter script is going to be included on a page within another folder, this file should be uploaded to the same folder as the page where the hit counter will be included. Hence the importance of the relative path variable at the top of this file. Also, this method will allow you to access the script from multiple pages within various folders across your website, to record site-wide traffic statistics.
3. Give this file, hit_counter_config.php, a permition of 600 to ensure security.
4. Use the examples contained within the file "Sample.htm.php" to learn how to implement this script on your web pages.
*/
?>
Requirements1. PHP V 4 or 5.
2. At least one website hit per day.
Download
Copyright © GutterStar.net. All rights reserved.
|
|||||||||||