Web counter

fegima

Registered
It would be nice if someone here could help me out.
I wonder if anyone knows how to create a webcounter that reads the apace log file to se how many that has been on the site. It will be nice in php to.

thank you
 

Isn't it useful that I was working on just this :cool:

This will go through your Apache access_log file and count line by line for occurances of the script file that's calling it.

If you want to monitor specific files just change $_SERVER['PHP_SELF'] to a static value like "mystore.html" or something...

Example http://amras.no-ip.com/acounter/count.php

You can use image creation commands to jazz it up if you like.

Code:
<?php

####
# 
#  Counts the number of times self is accessed in
#  /private/var/log/httpd/access_log
# 
#
#  Written by: Michael Sanford
#  It's a counter, copy at will!           
#   
####

// Set the count to zero.
$count = 0;

// Open the Apache log file (default installation location).
$accessLogHandle = fopen("/private/var/log/httpd/access_log", "r");

// Go through the file looking for the calling script's name.
while (!feof($accessLogHandle)) {
        $haystack = fgets($accessLogHandle, 4096);
        $position = strpos($haystack, $_SERVER['PHP_SELF']);
        if ($position) $count++;
        // Diagnostic output 
        // echo $haystack . "\t<b>" . $count . "</b><br>";
}

// Close the apache log file. 
fclose($accessLogHandle);

// Print the information
echo "<b>" . $_SERVER['PHP_SELF'] . "</b> has been accessed <b>" . $count . "</b> times.";

?>
 
Originally posted by ChoMomma
Use Safari :) no pop-ups :D
I can't quite put my finger on why, but I don't like Safari...

Also I did some testing this week to try to figure out when exactly Sarari does and does not block pop-up. From my testing it failed to block 3/4 of the popups on our site, but I could not figure out the criteria or pattern for why only some worked... (Oddly it blocked a login popup but failed to block an ad???)

I did some searching on Apple.com and Google to try to find technical details but could not. (Lots of marketing blather though...) If anyone could point me to the right place, I'd appreciate it.
 
Back
Top