Skip to main content
Topic: Counting server hits, tracking (Read 5381 times) previous topic - next topic

Counting server hits, tracking

Question for the Firmware / Software writing intelligencia from the great unwashed hardware geek :-)
OK, I wanted to add a Hit Counter to the Micro Server site and added the code I use on my other (regular ISP hosted) site and it fails to count :-( The counter box shows up on the index page of course but instead of a line of numbers there is a message about not being able to find the source or something.    It appears the counters I've tried (quite a few) even some purporting to be stand alone types all seem to need a connection to the www to do their data storage?
Please excuse my ignorance but software  / firmware ain't my strong point obviously :-)
Can anyone point me in the right direction to a simple counter I can add to the Micro Server index page code so I can actually see how many hit's the page is getting.
Thanks in advance guy's for any clues (or abuse :-)
Dave (the hardware guy  :-)
Dave (VA7DB)

Counting server hits, tracking

Reply #1
It should be easy enough. Most hit counters are just images embedded in a page and the service's server counts the number of image calls. The wsbc shouldn't have to do anything but serve the HTML with the image tag in it.

Can you post some sample code you've tried? We should be able to come up with something simple you can just put on the SD card and get working.
Got a question? Please ask in the forum for the fastest answers.

Counting server hits, tracking

Reply #2
Thanks for the quick reply Ian, this works as is on my ISP driven web page and all I did was remove the "You are visitor #" as I just wanted the basic counter window on the micro server.

You are visitor #

Probably me doing or expecting something silly :-)    Dave
Dave (VA7DB)

Counting server hits, tracking

Reply #3
I think it has to do with the referer. That service wants the browser to tell it how it got there with a referer link in the HTTP header, but I think the simplicity of the web server's HTTP headers are messing it up.

For example, when I paste the link in my browser it says 'bad or missing HTTP_referer'. I'd guess it's a mechanism to make sure that people don't pump the graphic with a script to increase page views.

When I visit the server with Firefox, here's the headers I get:
Content-Type: text/html
And the browser probably makes the referer the IP address (http://154.20.xxx.xxx:81/), which the tracking sites kill as fraud.

I can put together a very simple tracking script in PHP and host it here at whereisian.com, if you like. Then we can all see the hit count. We just have to make a one pixel image and count the number of times it's served.

Sorry, I saw this before bed and forgot to answer yesterday.
Got a question? Please ask in the forum for the fastest answers.

Re: Counting server hits, tracking

Reply #4
This is a really interesting topic, so I split it into a separate thread.
Got a question? Please ask in the forum for the fastest answers.

Re: Counting server hits, tracking

Reply #5
Here's my tracking software attempt.

I put together a PHP script that reads a text file called counter.txt and increments it. It also spits out a 1x1pixel PNG image file. The source is attached to this message.

Quote
//based on:
//http://www.xfunda.com/index.php?option=com_content&view=article&id=67:image-based-hit-counter-in-php-to-keep-track-of-visitor&catid=41:php&Itemid=44
//create a counter.txt file, CHMOD it to 0777, be sure to enter 0 to start or you get an error

//Opening file to get counter value
$file="counter.txt";
$fp = fopen ($file, "r");
$count_number = fread ($fp, filesize ($file));
fclose($fp);

//convert to integer, increment, convert to string...
$count_number = (string)( ( (int)($count_number) ) + 1 );

//save the incremented number
$fp = fopen ($file, "w");
fwrite ($fp, $count_number);
fclose($fp);

//push a 1px image
//based on:
//http://web.they.org/software/php-push.php
$file = "1px.png";
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-type: image/png");
header("Content-size: " . filesize($file));
readfile($file);
?>

You can embed it in a page with an html image tag:
Quote

The vulgarities of click tracking are immediately apparent. My browser hits the page three times each refresh in an attempt to 'preload' and do other speed tricks.

If you'd like to use it, let me know and I'll make a personal copy that starts at 0.
Got a question? Please ask in the forum for the fastest answers.

Re: Counting server hits, tracking

Reply #6
Wow, Ian,  Thanks very much for the in depth way you have offered to assist me (us) with a counter.....  I would love a little counter but hesitate to burden you with writing the software and taking up your valuable time........Please only do this for me if you have time to spare and know that I owe ya one my friend !
Dave
Dave (VA7DB)

Re: Counting server hits, tracking

Reply #7
Server Lock-Ups......anyone else seeing the little web server locking up?    If left on it'll lock up at least a couple of times a day.
Did anyone try monitoring the watchdog pin on the PIC or have any suggestions how ro reset the PIC if it craps out?
If all else fails just have a regularly timed reset?
I agree with Ramon too, it'd be nice to see and display the incoming users IP....any thoughts on how to do this welcome.
Myself and a buddy currently have LED's attached to the three spare outputs of the PIC and if you go on line can switch them on and off, thanks to Ramon's stellar efforts in coding.  Be warned now that is is slow to load the page initially!
Dave
Dave (VA7DB)